[net.bugs] CSH `...` purposeful on first word; EVAL bugs explained

idallen@watmath.UUCP (07/23/84)

The C Shell is designed to do the first "word" of the input as a
separate entity from the rest of the arguments, so if you type

    `command` arg1 arg2 arg3

you can be sure that `command` will expand to at most one word and
your supplied arguments will still be numbers 1, 2 and 3 to that
command.  It isn't hard to rewrite that a part of the shell to remove
this restriction, but you have to decide if you really want to change it.

As pointed out, giving the command to the EVAL built-in will remove
the restriction for you, but you have to be careful of the other CSH
bug where redirection of I/O and pipes are ignored for the first
command inside the EVAL, e.g.:

    eval "who|sort"     # the sort is ignored; WHO appears on tty
    eval "who" |sort    # this works
    eval "date >x"      # the ">x" is ignored; DATE appears on tty
    eval "date" >x      # this works
    eval "date|who|sort"# the pipe between date|who is ignored; who|sort works
    eval "date|who >x"  # the pipe between date|who is ignored; who >x works
    eval "date|users >x;echo hi" >y
       # DATE goes to Y, USERS to X, and HI to the tty (!)

This is because the EVAL built-in doesn't preserve and redo its file
descriptors for the commands it's about to execute.  I have a fix; but,
it's in with my other 20 pages of C Shell bug descriptions.  You'll
know you got the fix right if this works:

   echo "eval 'who|sort' | grep tty" | eval `cat` >xxx
-- 
        -IAN!  (Ian! D. Allen)      University of Waterloo