csh quoting question: nested command substitution

Rouben Rostamian rouben at math9.math.umbc.edu
Thu Jul 26 14:00:56 AEST 1990


In article <4031 at rodan.acs.syr.edu> jdpeek at rodan.acs.syr.edu (Jerry Peek) writes:
 >Okay, I can tell that I obviously don't understand csh quoting.
 >I want to set the csh prompt, but this question is really more generic
 >than prompt-setting.
 >
 >In the Bourne shell, I can do:
 >	PS1="`/bin/expr \`/bin/hostname\` : '\([^.]*\)'`$ "
 >which runs basename, then strips off anything after the local host name.
 >So, if /bin/hostname prints rodan.acs.syr.edu, the prompt is rodan$.
 >And, if /bin/hostname prints rodan, the prompt is still rodan$.
 >
 >I know there are lots of other ways to do this (pipe to sed, store
 >hostname output in a shell variable first, etc.).
 >But I want to do it in csh, in a nice one-liner like sh lets me.
 >No matter what I do, I get some kind of syntax error.
 >Can someone at least tell me how... and, better, tell me *why*?  Thanks.

In csh you achieve the same effect by:

   set prompt = `/bin/hostname | /usr/bin/cut -d. -f1`'$ '

I do not know why your expr syntax does not work in csh.  In fact, I am
surprised that the nested expression evaluation with ` ` works in sh
to begin with.  Does sh make two passes, first evaluating /bin/hostname
and then executing expr?  

--
 
Rouben Rostamian                               Telephone: (301) 455-2458
Department of Mathematics and Statistics       e-mail:
University of Maryland Baltimore County        rostamian at umbc.bitnet
Baltimore, MD 21228,  U.S.A.                   rostamian at umbc3.umbc.edu



More information about the Comp.unix.questions mailing list