Wednesday, April 16, 2014

csh tcsh alias command line argument

# vi ~/.cshrc
alias ee 'echo \!:1 secondArg'

# source ~/.cshrc

# ee firstArg
firstArg secondArg

Alias argument selectors; the ability to define an alias to take arguments supplied to it and apply them to the commands that it refers to. Tcsh is the only shell that provides this feature.

  • \!# - argument selector for all arguments, including the alias/command itself; arguments need not be supplied.
  • \!* - argument selector for all arguments, excluding the alias/command; arguments need not be supplied.
  • \!$ - argument selector for the last argument; argument need not be supplied, but if none is supplied, the alias name is considered to be the last argument.
  • \!^ - argument selector for first argument; argument MUST be supplied.
  • \!:n - argument selector for the nth argument; argument MUST be supplied; n=0 refers to the alias/command name.
  • \!:m-n - argument selector for the arguments from the mth to the nth; arguments MUST be supplied.
  • \!:n-$ - argument selector for the arguments from the nth to the last; at least argument n MUST be supplied.

http://en.wikipedia.org/wiki/Tcsh

No comments: