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

2008-06-26 Thread Juri Mianovich

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 ?

Thanks.


  

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


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

2008-06-26 Thread Derek Ragona

At 07:04 AM 6/26/2008, 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 ?

Thanks.



I think you are trying to use an alias where it won't really work.  A 
typical alias is:

la  for ls -a
ll  for ls -lA

It looks like you want to pass an argument and a filename, or at least an 
argument to grep.  Not quite sure if that would work or if it would be much 
use.


The $ is a special character that is interpreted and expanded by the 
shell.  You can use it by escaping it or putting it in quotes, but that 
depends on where it is used (in .cshrc, in a script, etc.)


-Derek

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


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

2008-06-26 Thread Pietro Cerutti

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA512

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 ?


Try with \!\!:1

Example:

alias say   echo 'I say \!\!:1'

| say hello
I say hello

|
| Thanks.

You're welcome.

- --
Pietro Cerutti
[EMAIL PROTECTED]

PGP Public Key:
http://gahr.ch/pgp

-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.9 (FreeBSD)

iEYEAREKAAYFAkhjqFkACgkQwMJqmJVx944z4QCeKf5wirL9TOqAy0QhyUt7f0mE
/2AAoJB1nkUYSfd4/QEdmJUEENaUsA12
=zK3x
-END PGP SIGNATURE-
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


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

2008-06-26 Thread N. Raghavendra
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 [EMAIL PROTECTED] | http://www.retrotexts.net/
Harish-Chandra Research Institute   | http://www.mri.ernet.in/
See message headers for contact and OpenPGP information.

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]