why can't I use $1 in .cshrc ?

N. Raghavendra raghu at mri.ernet.in
Thu Jun 26 15:10:13 UTC 2008


At 2008-06-26T05:04:52-07:00, Juri Mianovich wrote:

> I am trying to use this alias in my root .cshrc file:
>
> grep $1 /some/file
>
> but .cshrc _refuses_ to expand $1 as a proper variable (in this
> case, the first argument to the alias...)
>
> I _think_ it's because $1 is being interpreted as a argument to csh
> _itself_ when it runs .cshrc ... but maybe I'm wrong.
>
> Anyway, how to make it work ?

See the tcsh(1) section `Alias substitution':

  "If the alias contains a history reference, it undergoes History
  substitution (q.v.) as though the original command were the previous
  input line."

[riemann:/home/raghu]% alias foo "grep \!^ /etc/passwd"
[riemann:/home/raghu]% foo toor
toor:*:0:0:Bourne-again Superuser:/root:

[riemann:/home/raghu]% alias bar "grep \!:1 \!:2"
[riemann:/home/raghu]% bar '^man' /etc/passwd
man:*:9:9:Mister Man Pages:/usr/share/man:/usr/sbin/nologin

HTH,
Raghavendra.

-- 
N. Raghavendra <raghu at mri.ernet.in> | http://www.retrotexts.net/
Harish-Chandra Research Institute   | http://www.mri.ernet.in/
See message headers for contact and OpenPGP information.



More information about the freebsd-questions mailing list