spacer
Web Development Tutorials LINUX Tutorials
 Developer Newsletter

Tutorials
AJAX
ASP
CGI & Perl
CSS
Flash
HTML
Illustrator
Java
JavaScript
Linux
MySQL
PHP
Photoshop
Python
Wireless
XML
Miscellaneous


Scripts Directory
AJAX Scripts
ASP Scripts
ASP.NET Scripts
CGI & Perl Scripts
Flash Scripts
Java Scripts
JavaScript Scripts
PHP Scripts
Python Scripts
Remotely Hosted Scripts
Tools & Utilities Scripts
XML Scripts

Web Hosting Directory
ASP.NET
Budget
Dedicated Servers
Ecommerce
Linux
Resellers
Shared
Small Business
Windows

Developer Manuals
Learn HTML
Learn PHP
Learn CSS
Learn AJAX
Learn JavaScript
Learn Pear
Free White Papers

Developer Resources
Developer Tools
Developer Content
Survey Software
Dedicated Servers




Bash Aliases

By Tony Lawrence
2005-09-02


Bash aliases

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 aliases

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 yo, 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.



Tutorial Pages:
» Bash aliases


© Copyright 2005 A.P. Lawrence


 | Bookmark Print |   Write For Us
Related Tutorials:
» How to Install PHP 5 on Linux
» How to Install Apache 2 on Linux
» How to Install MySQL 5.0 on Linux
» SMB Caching
» Mound --Bind
» Tar Wild Card Interpretation



About the NetVisits, Inc Network | Write For Us | Advertise
Copyright ©2007 NetVisits, Inc Network. All Rights Reserved. Privacy Policy.
Visit other NetVisits, Inc. sites: