dfoster@jarthur.Claremont.EDU (Derek R. Foster) (04/17/91)
AAAAAAAAAAAAAAAAAAAUUUUUUUUUUUUUUGGGGGGGGGGGGGGHHHHHHHHHHHHHHHHH!!!!!!!!!!! Consider the following: > 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?) > cat > testx <- make a file called testx echo "abc def" EOF >source testx <- it works as expected abc def > setenv A "`source ./testx`" <- even in the setenv with backquotes > printenv A abc def <- 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. If anyone can shed some light on this behavior, I would be very happy. All I want to do is set an environment variable to the output of a shell script run via 'source', yet with every possible permutation I've tried with all kinds of combinations of ', `, ", and \ placed in interesting places, I have still consistently received the same bizarre results. WHY?????? Derek Riippa Foster
jik@athena.mit.edu (Jonathan I. Kamens) (04/23/91)
In article <11744@jarthur.Claremont.EDU>, dfoster@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@Athena.MIT.EDU Allston, MA 02134 Office: 617-253-8085 Home: 617-782-0710
chet@odin.INS.CWRU.Edu (Chet Ramey) (04/23/91)
In article <1991Apr23.004314.17527@athena.mit.edu> jik@athena.mit.edu (Jonathan I. Kamens) writes: >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. It was Chris Torek. Perhaps if you asked very nicely, he would explain it again ;-) Chet -- Chet Ramey Internet: chet@po.CWRU.Edu Case Western Reserve University NeXT Mail: chet@macbeth.INS.CWRU.Edu ``Now, somehow we've brought our sins back physically -- and they're pissed.''
christos@theory.tn.cornell.edu (Christos S. Zoulas) (04/24/91)
In article <1991Apr23.154211.8976@usenet.ins.cwru.edu> chet@po.CWRU.Edu writes: >It was Chris Torek. Perhaps if you asked very nicely, he would explain it >again ;-) Since I'll fixed it for tcsh, I'll try to explain... (Though my explanation is not going to be as good as Chris Torek's) Csh in many places, is using a routine called globone() to expand regular expressions. This routine will produce an error if the regular expression expands to more (or less than) one word. If the regular expression expands to more than one word, then globone() will complain 'blah: Ambiguous.'; if it expands to less than one word it will say 'blah: No match.'. (blah is the offending regular expression) Unfortunately this routine is used in many places in csh, and here's a list of some of the most annoying ones: % kill `echo 1 2 3` % `echo date -u` % setenv FOO `echo 1 2 3` % echo foo > `echo 1 2 3` In some cases you can quote the regular expression to achieve the desired result (example 3, maybe 4). In cases 1 and 2 though it is the csh code that needs fixing... christos -- Christos Zoulas | 389 Theory Center, Electrical Engineering, christos@ee.cornell.edu | Cornell University, Ithaca NY 14853. christos@crnlee.bitnet | Phone: (607) 255 0302, Fax: (607) 255 9072