Return to BSD News archive
Xref: sserve comp.unix.user-friendly:2865 comp.unix.solaris:22652 comp.unix.programmer:19931 comp.unix.misc:13840 comp.unix.aux:15459 comp.unix.bsd:14862 comp.unix.aix:43877
Path: sserve!newshost.anu.edu.au!harbinger.cc.monash.edu.au!news.cs.su.oz.au!metro!wabbit.cc.uow.edu.au!picasso.cssc-syd.tansu.com.au!newshost!chrisb
From: chrisb@wombat.cssc-syd.tansu.com.au (Chris Bitmead)
Newsgroups: comp.unix.user-friendly,comp.unix.solaris,comp.unix.programmer,comp.unix.misc,comp.unix.aux,comp.unix.bsd,comp.unix.aix
Subject: Re: Shell wars
Date: 7 Sep 94 15:52:37
Organization: Telecom Australia - CSSC
Lines: 70
Distribution: inet
Message-ID: <CHRISB.94Sep7155237@wombat.cssc-syd.tansu.com.au>
References: <33af70$8rd@usenet.INS.CWRU.Edu> <ROCKWELL.94Sep2081402@nova.umd.edu>
<34d3f2$ca@sprocket.csv.warwick.ac.uk> <ROCKWELL.94Sep4164530@nova.umd.edu>
<34eppt$919@sprocket.csv.warwick.ac.uk>
<34hk79$l83@rockall.cc.strath.ac.uk>
NNTP-Posting-Host: wombat.cssc-syd.tansu.com.au
In-reply-to: sinclair@dis.strath.ac.uk's message of 6 Sep 1994 11:36:09 GMT
>In <34eppt$919@sprocket.csv.warwick.ac.uk> cudcv@csv.warwick.ac.uk (Rob McMahon) writes:
>>In article <ROCKWELL.94Sep4164530@nova.umd.edu>, rockwell@nova.umd.edu (Raul
>>Deluth Miller) writes:
>>>. >lpr `set | egrep \^lpargs | cut -d= -f2-`
>>>
>>>. Sorry, it doesn't work. This splits all the arguments at white
>>>. space (returning 9 arguments "x" "y" "z" "x" "y" "z" "x" "y" "z"
>>>. instead of 3 "x y z" "x y z" "x y z" in the example. Using quotes:
>>>
>>>Sorry, I don't normally worry about that issue. Try
>>>
>>>eval lpr `set | egrep \^lpargs | cut -d= -f2- | while read l; do echo
>>> \"$l\"; done`
>>Still doesn't work. I now get the 9 arguments '"x' 'y' 'z"' '"x' 'y' 'z"'
>>'"x' 'y' 'z"'.
>Indeed, the bourne shell has problems with preserving quoting
>in arguments passed between programs. The "$@" hack was invented
>specifically to address this problem, but it is not a total solution.
Well, I don't know if you'd call it hack. In any case it works.
>Much better to stop this {k,ba,}sh vs {t,}csh bickering and using
>a shell like zsh or rc where the problem just doesn't occur.
Maybe, but rc is too primitive for interactive use, and zsh is a bit
bloated. (Although I use it).
>In zsh:
> foo="x y z"
> lpargs=($foo $foo $foo)
> lpr $lpargs
>Will work - no mess, no fuss.
True, but I hardly ever need to do this sort of thing anyway. It is of
course possible to do this in standard bourne shell with a bit of imagination:
V1='a b c'
V2='d e f'
V3='g h i'
for i in 1 2 3
do
eval 'X="$X \"\$V'$i'\""'
done
eval "for i in $X ; do echo hello >\$i ; done"
ls -l ?????
-rw-rw-r-- 1 chrisb 6 Sep 7 09:47 a b c
-rw-rw-r-- 1 chrisb 6 Sep 7 09:47 d e f
-rw-rw-r-- 1 chrisb 6 Sep 7 09:47 g h i
Or for the lpr example:
eval "lpr $X"
In other words, arrays are fully possible in standard bourne shell,
although they are inconvenient. I don't usually find arrays terribly
useful, but there are times I wish the shell supported them.
In any case, someone can wrap up the above concepts into shell functions
or scripts, if you really need to use them with standard sh.