Csh setenv and `` don't like each other!
Jonathan I. Kamens
jik at athena.mit.edu
Tue Apr 23 10:43:14 AEST 1991
In article <11744 at jarthur.Claremont.EDU>, dfoster at jarthur.Claremont.EDU (Derek R. Foster) writes:
|> > alias test 'echo "Test OK"' <- Define an alias...
|> > test <- It works correctly
|> TEST OK
|> > echo `test` <- Even in backquotes
|> TEST OK
|>
|> > setenv A `test` <- But not after setenv. WHY?
|> `test`: Ambiguous <- What on earth does "Ambiguous" mean here?
|> <- (Why on earth do UNIX system programmers
|> <- fear self-explanatory error messages so
|> <- much?)
At some point in the past, this question was brought up in the context of
why this doesn't work:
kill `echo 255 256`
`echo 255 256`: Ambiguous.
but this does:
/bin/kill `echo 255 256`
Someone who knows far more about the internals of csh than I do (I believe it
was Doug Gwyn, although my memory may be failing here) posted a very good
explanation of what's going wrong here. I was hoping that whoever posted that
explanation last time would post it again, because I didn't save it, but it's
been five days and that hasn't happened, so I'll take a stab at trying to
explain what's going on (since the article is going to expire from my spool in
a day or so :-).
First of all, I should point out that the shell *is* correct to complain
about
setenv A `test`
because the setenv command takes two arguments, and you're passing it three
("A", "Test", and "OK"). The problem is that, because of csh brain-damage
when parsing arguments to builtin functions, it doesn't quite get the correct
error message. Things work when you do
setenv A "`test`"
or at least they do for me:
% alias test 'echo "Test OK"'
% setenv A "`test`"
% echo $A
Test OK
%
The "ambiguous" error is telling you that csh is expecting to see one
argument at that point in the command line, and it's seeing multiple arguments
instead. The problem, I believe, is that the backquote substitution takes
place too place for the code that checks for "too many arguments" (the correct
error) to notice it.
|> <- but for another file....
|> > echo "`source /hmc2/hmc_1993/dfoster/project2/host_supports`"
|> jove vi tex msg
|>
|> <- it breaks, and the program is never run.
|> > setenv A "`source /hmc2/hmc_1993/dfoster/project2/host_supports`"
|> `source /hmc2/hmc_1993/dfoster/project2/host_supports`: Ambiguous.
What is in the file /hmc2/hmc_1993/dfoster/project2/host_supports? I can't
seem to duplicate this problem:
% cat > /tmp/host_supports
echo "jove vi tex msg"
% echo "`source /tmp/host_supports`"
jove vi tex msg
% setenv A "`source /tmp/host_supports`"
% echo $A
jove vi tex msg
Without more information, it's difficult to tell you why you're having this
problem or how to solve it.
--
Jonathan Kamens USnail:
MIT Project Athena 11 Ashford Terrace
jik at Athena.MIT.EDU Allston, MA 02134
Office: 617-253-8085 Home: 617-782-0710
More information about the Comp.unix.shell
mailing list