*BSD News Article 91248


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!news.mira.net.au!news.netspace.net.au!news.mel.connect.com.au!munnari.OZ.AU!news.ecn.uoknor.edu!news.ysu.edu!news.radio.cz!newsbastard.radio.cz!news.radio.cz!CESspool!news.maxwell.syr.edu!dispatch.news.demon.net!demon!netcom.net.uk!nntpfeed.doc.ic.ac.uk!sunsite.doc.ic.ac.uk!lyra.csx.cam.ac.uk!news
From: Gareth McCaughan <gjm11@dpmms.cam.ac.uk>
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: Re: A simple csh script question
Date: 17 Mar 1997 18:18:04 +0000
Organization: International Pedant Conspiracy
Message-ID: <86d8sy757n.fsf@g.pet.cam.ac.uk>
References: <332D9485.27FD@inJapan.net>
NNTP-Posting-Host: g.pet.cam.ac.uk
X-Newsreader: Gnus v5.3/Emacs 19.34
Lines: 28
Xref: euryale.cc.adfa.oz.au comp.unix.bsd.freebsd.misc:37193

Doug Lerner <doug@inJapan.net> writes:

> Can somebody answer a simple csh script question for me? In the
> following script, the last line won't work unless I add "eval" to the
> front of the line. Without eval, the "~" mark does not cause the
> expansion to the user's home directory, like it usually does. Why might
> that be?
...
> #!/bin/sh
...
> eval ls ~$id | grep forward

I note that you mean "sh", not "csh". (I haven't checked whether it
matters.) The reason why ~$id doesn't work is that tilde expansion
and parameter expansion happen "at the same time" (as the manpage
puts it). The effect you want would only happen if parameter expansion
happened first.

Putting "eval" in front of the whole thing seems rather heavyweight.
How about:

    ls $(~$id) | grep forward

?

-- 
Gareth McCaughan       Dept. of Pure Mathematics & Mathematical Statistics,
gjm11@dpmms.cam.ac.uk  Cambridge University, England.