Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 26 Jun 2008 20:35:21 +0530
From:      "N. Raghavendra" <raghu@mri.ernet.in>
To:        juri_mian@yahoo.com
Cc:        freebsd-questions@freebsd.org
Subject:   Re: why can't I use $1 in .cshrc ?
Message-ID:  <867iccp77y.fsf@riemann.mri.ernet.in>
In-Reply-To: <510944.89845.qm@web45604.mail.sp1.yahoo.com> (Juri Mianovich's message of "Thu, 26 Jun 2008 05:04:52 -0700 (PDT)")
References:  <510944.89845.qm@web45604.mail.sp1.yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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@mri.ernet.in> | http://www.retrotexts.net/
Harish-Chandra Research Institute   | http://www.mri.ernet.in/
See message headers for contact and OpenPGP information.




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?867iccp77y.fsf>