Aliases

Use aliasing mechanism to assign a sequence of commands to a name.

Properties

  
* C-shell version of alias can use history to take arguments, 
   but also did not have a function mechanism.

  Bash does have functions. Use these for more complex definitions.


Creation, listing, removal.

  • Creating alias alias_name="command sequence"
  • Listing existing aliases. alias alias target_alias
  • Deleting unalias target_alias Exporting Because an alias is NOT exportable, 1. Place your alias definition in .bashrc in your $HOME directory. 2. Invoke .bashrc from .bash_profile in your $HOME directory. Getting inteactive input from user Although the bash alias cannot use the history mechanism to get arguments from the command line. It can use the shell built-in read function to read input directly from the user. The following alias prompts the user for two filenames and then swaps their contents. alias swapper='read -p "1st file : " fn1; e read -p "2nd file : " fn2; mv $fn1 ${fn1}.tmp; mv $fn2 $fn1; mv ${fn1}.tmp $fn2' Note the following : This is a rather long alias, so it is best to edit it in a file and then source the file. Be careful, there are no line breaks in this. Because there are variable references in the alias, the whole alias is single quoted to prevent evaluation of variables during alias assignment.