jdpeek@rodan.acs.syr.edu (Jerry Peek) (07/26/90)
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. --Jerry Peek; Syracuse University Academic Computing Services; Syracuse, NY jdpeek@rodan.acs.syr.edu, JDPEEK@SUNRISE.BITNET +1 315 443-3995
rouben@math9.math.umbc.edu (Rouben Rostamian) (07/26/90)
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