# # Bash aliases
APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

Bash aliases

I've removed advertising from most of this site and will eventually clean up the few pages where it remains.

While not terribly expensive to maintain, this does cost me something. If I don't get enough donations to cover that expense, I will be shutting the site down in early 2020.

If you found something useful today, please consider a small donation.



Some material is very old and may be incorrect today

© September 2005 Tony Lawrence

Most shells have some provision for aliases. Aliases can assign default behavior to a command (for example "rm" is often aliased to "rm -i") or can be used to create new commands (a typical example is "ll" aliased to be "ls -l").

Aliases are expanded before looking in $PATH. Depending upon your Bash settings, a "which" for a over-ride alias like "rm" may show you the commands found in $PATH also:



bash-2.01$ which rm
rm:      aliased to rm -i

# a different machine
bash-2.05b$ which rm
alias rm='rm -i'
        /bin/rm
 

To get the second behavior, 'which' itself was aliased :

bash-2.05b$ which which
alias which='alias | /usr/bin/which --tty-only --read-alias 
--show-dot --show-tilde'
        /usr/bin/which
 

Aliases are NOT normally expanded in non-interactive shells, which means that if you use "rm" in a script, you won't get the alias - unless you want to, in which case you do "shopt -s expand_aliases" before calling it. If you want to be safe, use /bin/rm instead, which can't ever be confused with an alias.

There are other confusing rules for alias expansion; even the man page admits the potential for gross misunderstanding and follows that confession with this:

For almost every purpose, aliases are superseded by shell functions.

You might construe that as an apology of sorts, but while the maintainers of Bash might fondly hope (and have excellent reasons for hoping) for that to be true, in fact and in common practise, aliases continue to be used regularly and I have little doubt that will remain true for a long, long time.


If you found something useful today, please consider a small donation.



Got something to add? Send me email.





(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

->
-> Bash aliases


Inexpensive and informative Apple related e-books:

Take Control of iCloud, Fifth Edition

Take Control of IOS 11

Take Control of Numbers

El Capitan: A Take Control Crash Course

iOS 8: A Take Control Crash Course





More Articles by © Tony Lawrence





Printer Friendly Version

Have you tried Searching this site?

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us


Printer Friendly Version





The use of COBOL cripples the mind; its teaching should, therefore, be regarded as a criminal offence. (Edsger W. Dijkstra)




Linux posts

Troubleshooting posts


This post tagged:

Linux

Scripting

Shell

Unix



Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode