Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unix tcsh - alias using command line argument $1 versus \!:1

Tags:

unix

tcsh

In Unix (tcsh), I've referenced command line arguments in my aliases with two different notations - $1 and \!:1.

But I noticed that if I try to save $1 to an environment variable, it doesn't get saved. However \!:1 does get saved.

alias hear 'setenv x \!:1 && echo $x'
--> hear that
that
--> echo $x
that

alias oh 'setenv x $1 && echo $x'
--> oh no
no
--> echo $x

Nothing shows up on the echo of $x when $1 is used to store the value. What is the reason for this?

like image 446
itchmyback Avatar asked Oct 19 '13 20:10

itchmyback


1 Answers

$1 returns the first argument passed to the script that contains the alias command. So if you are calling it from the command line, it will return nothing.

\!:1 returns the first argument passed to the aliased command, so that is clearly what you should be using.

like image 81
supergra Avatar answered Sep 27 '22 19:09

supergra