weird csh thing
Frank P. Bresz
fpb at ittc.wec.com
Tue Jan 8 11:11:31 AEST 1991
In article <BAGCHI.91Jan6000722 at snarf.eecs.umich.edu> bagchi at eecs.umich.edu (Ranjan Bagchi) writes:
>anyone care to explain?? (I`m in csh)
>$ set p = "w | tail +3 "
>$ echo $p
>w | tail +3
>$ $p
>Usage: w [ -hlsuw ] [ user ]
>$ w | tail +3
>benjo ttyp3 10:13pm 41 4 -sh
>benjo ttyp4 10:17pm 3:22 4 -csh
>$ exit
>$ exit
>Process shell finished
>shouldn't "$p" have the same effect as "w | tail +3" ?
> -rj
Well,
I'll take a shot at an explanation.
By saying:
set p = "w | tail +3 "
You have effectively escaped the normal behavior of | which is to
run a pipe to the next command in line. Thereby passing the | to the 'w'
command as the first argument. 'w' does not understand what the '|'
symbol means so it spits out it's usage command. This command shows what I
mean:
ittc% w \| tail +3
Usage: w [ -hlsuw ] [ user ]
Had you instead said :
eval $p
You would have received the 'w' portion only the 'tail' would not
execute, (at least it didn't under my csh SunOS4.1, why I don't know).
This scenario worked for both bash and sh.
$ p="w | tail +3"
$ $p
Usage: w [ -hlsuw ] [ user ]
$ eval $p
fpb console 12:44pm 6:15 9:32 9:27 sv_xv_sel_svc
young ttyh5 12:40pm 5:54 telnet wssi3
young ttyha 11:29am 6:46 5 5 telnet wssi3
miller ttyhc 2:33pm 3:33 3 -csh
fpb ttyp0 12:44pm 28 /emacs/sun4/etc/bash
fpb ttyp3 6:26pm 9 1 w
mance ttyp9 3:10pm 3:49 -
In CSH however I tried and received :
ittc% set p = " w | tail +3 "
ittc% $p
Usage: w [ -hlsuw ] [ user ]
ittc% echo $p
w | tail +3
ittc% eval $p
7:03pm up 2 days, 12:04, 6 users, load average: 1.60, 2.24, 2.05
User tty login@ idle JCPU PCPU what
fpb console 12:44pm 6:19 9:45 9:40 sv_xv_sel_svc
young ttyh5 12:40pm 5:58 telnet wssi3
young ttyha 11:29am 6:50 5 5 telnet wssi3
miller ttyhc 2:33pm 3:37 3 -csh
fpb ttyp0 12:44pm 32 /emacs/sun4/etc/bash
fpb ttyp3 6:26pm 10 1 w
mance ttyp9 3:10pm 3:54 -
ittc%
Clearly the tail failed. Any CSH wizards know why. I received
bash about 4 months ago and haven't touched csh since. Out of pure
inquisitiveness what is wrong with :
alias p "w | tail +3"
p
--
| () () () | Frank P. Bresz | Westinghouse Electric Corporation
| \ /\ / | fpb at ittc.wec.com | ITTC Simulators Department
| \/ \/ | uunet!ittc!fpb | Those who can, do. Those who can't, simulate.
| ---------- | +1 412 733 6749 | My opinions are mine, WEC don't want 'em.
More information about the Comp.unix.shell
mailing list