How is && supposed to work in csh?
Richard O'Keefe
ok at cs.mu.oz.au
Sat Oct 21 19:45:12 AEST 1989
In article <89293.143521BACON at MTUS5.BITNET>, BACON at MTUS5.BITNET (Jeffery Bacon) writes:
> if ( -f /bin/sun4 ) /bin/sun4 && set arch=sun4 && goto gotarch
> if ( -f /bin/sun4c ) /bin/sun4c && set arch=sun4 && goto gotarch
> if ( -f /bin/sun3 ) /bin/sun3 && set arch=sun3 && goto gotarch
> if ( -f /bin/sun3x ) /bin/sun3x && set arch=sun3 && goto gotarch
> gotarch:
The csh(1) manual page says about
if (expr) command
that "command must be a simple command, not a pipeline, a command
list, or a parenthesized command list." One of the possible cases
for a pipeline is a sequence of commands separated by "&&".
A simpler scheme would be to do
if (-f /bin/sun4 && { /bin/sun4 }) then
set arch=sun4
else if (-f /bin/sun4c && { /bin/sun4c }) then
set arch=sun4
else if (-f /bin/sun3 && { /bin/sun3 }) then
set arch=sun3
else if (-f /bin/sun3c && { /bin/sun3c }) then
set arch=sun3
else
echo "Unable to determine architecture type"
exit 1
endif
I find that it is generally better to write scripts using the Bourne shell
(sh) than the C shell (csh): the sh language has rather fewer gotchas. It
is also easier to do some things. For example, I would really like the
error message to come out on stderr rather than stdout. In sh it's easy:
echo "Unable to determine architecture type" >&2
Given that you are going to try running up to four programs /bin/sun{3,4}{,c}
anyway, it seems odd to boggle at using the /bin/arch script to do it.
More information about the Comp.unix.questions
mailing list