Difference between revisions of "Alias"

From Linuxintro
imported>ThorstenStaerk
imported>ThorstenStaerk
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
An alias is a string that stands for a command. For example you can define "greet" to be an alias for "echo 'hello world'" like this:
+
An alias is a string that stands for a command.  
 +
 
 +
= Bash shell =
 +
For example you can define "greet" to be an alias for "echo 'hello world'" in the [[bash]] [[shell]] like this:
 
  # alias greet="echo 'hello world'"
 
  # alias greet="echo 'hello world'"
 
  # greet
 
  # greet
 
  hello world
 
  hello world
  
 +
= csh shell =
 +
For example you can define "greet" to be an alias for "echo 'hello world'" in the csh [[shell]] like this:
 +
# alias greet "echo 'hello world'"
 +
# greet
 +
hello world
 +
 +
= Showing the definition =
 
So you can set an alias using the [[command]] alias. With this command you can also show the meaning of a alias:
 
So you can set an alias using the [[command]] alias. With this command you can also show the meaning of a alias:
 
  # alias dir
 
  # alias dir
 
  alias dir='ls -l'
 
  alias dir='ls -l'
 +
 +
Aliases are similar to shell functions, but you cannot display a function's definition while you can display an aliases' definition.
  
 
= Setting an alias =
 
= Setting an alias =
To set an alias persistently for all users, all shells ([[ksh]], [[bash]], ...) and all type of shells ([[login shells]] and non-login shells) you need to
+
To set an alias persistently for all users, all shells (csh, [[bash]], ...) and all type of shells ([[login shells]] and non-login shells) you need to
 
* modify /etc/profile
 
* modify /etc/profile
 
:for [[logIn shells]]
 
:for [[logIn shells]]
* modify /etc/bash_bashrc
+
* modify /etc/bash.bashrc
 
:for non-login [[bash]] [[shells]]
 
:for non-login [[bash]] [[shells]]

Latest revision as of 09:32, 19 September 2013

An alias is a string that stands for a command.

Bash shell

For example you can define "greet" to be an alias for "echo 'hello world'" in the bash shell like this:

# alias greet="echo 'hello world'"
# greet
hello world

csh shell

For example you can define "greet" to be an alias for "echo 'hello world'" in the csh shell like this:

# alias greet "echo 'hello world'"
# greet
hello world

Showing the definition

So you can set an alias using the command alias. With this command you can also show the meaning of a alias:

# alias dir
alias dir='ls -l'

Aliases are similar to shell functions, but you cannot display a function's definition while you can display an aliases' definition.

Setting an alias

To set an alias persistently for all users, all shells (csh, bash, ...) and all type of shells (login shells and non-login shells) you need to

  • modify /etc/profile
for logIn shells
  • modify /etc/bash.bashrc
for non-login bash shells