< Day Day Up > |
13.6. AliasesAn alias is a bash user-defined abbreviation for a command. Aliases are useful if a command has a number of options and arguments or the syntax is difficult to remember. Aliases set at the command line are not inherited by subshells. Aliases are normally set in the .bashrc file. Because the .bashrc is executed when a new shell is started, any aliases set there will be reset for the new shell. Aliases may also be passed into shell scripts but will cause potential portability problems unless they are set directly within the script. 13.6.1 Listing AliasesThe alias built-in command lists all set aliases. The alias is printed first, followed by the real command or commands it represents. Example 13.37.$ alias alias co='compress' alias cp='cp –i' alias mroe='more' alias mv='mv –i' alias ls='ls --colorztty' alias uc='uncompress' EXPLANATION The alias command lists the alias (nickname) for the command and the real command the alias represents after the = sign. 13.6.2 Creating AliasesThe alias command is used to create an alias. The first argument is the name of the alias, the nickname for the command. The rest of the line consists of the command or commands that will be executed when the alias is executed. Bash aliases cannot take arguments (see "Defining Functions" on page 841). Multiple commands are separated by a semicolon, and commands containing spaces and metacharacters are surrounded by single quotes. Example 13.38.1 $ alias m=more 2 $ alias mroe=more 3 $ alias lF='ls -alF' 4 $ alias r='fc -s' EXPLANATION
13.6.3 Deleting AliasesThe unalias command is used to delete an alias. To temporarily turn off an alias, precede the alias name by a backslash. Example 13.39.1 $ unalias mroe 2 $ \ls EXPLANATION
|
< Day Day Up > |