Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!udel!haven!umbc3!math9.math.umbc.edu!rouben From: rouben@math9.math.umbc.edu (Rouben Rostamian) Newsgroups: comp.unix.questions Subject: Re: csh quoting question: nested command substitution Message-ID: <3656@umbc3.UMBC.EDU> Date: 26 Jul 90 04:00:56 GMT References: <4031@rodan.acs.syr.edu> Sender: newspost@umbc3.UMBC.EDU Reply-To: rouben@math9.math.umbc.edu.UUCP (Rouben Rostamian) Organization: Mathematics Department University of Maryland, Baltimore County Lines: 32 In article <4031@rodan.acs.syr.edu> jdpeek@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@umbc.bitnet Baltimore, MD 21228, U.S.A. rostamian@umbc3.umbc.edu