Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!caen!umich!sharkey!fmsrl7!art-sy!news From: chap@art-sy.detroit.mi.us (j chapman flack) Newsgroups: comp.unix.shell Subject: Re: csh setenv with `cat ...` Keywords: csh setenv with `cat ...` Message-ID: <9104292045.aa10390@art-sy.detroit.mi.us> Date: 30 Apr 91 00:45:14 GMT References: <6291@beryl12.UUCP> Sender: chap@art-sy.detroit.mi.us (j chapman flack) Reply-To: chap@art-sy.detroit.mi.us (j chapman flack) Distribution: comp Organization: Appropriate Roles for Technology Lines: 42 In article <6291@beryl12.UUCP> mostek@motcid.UUCP (Frank B. Mostek) writes: >I am having a problem with the csh setenv command: > >$setenv EXINIT `cat ~/.myexrc` >`cat ~/.myexrc`: Ambiguous. > Phooey. I'd never realized something could be so difficult in csh. According to `man csh' (which doesn't have a single word about the `Ambiguous' diagnostic, at least in my SCO SysV version), the result of a `command substitution` is the output of the command, with all whitespace, including newlines, turned into word delimiters--so even if the `stuff` *did* work, you would wind up with multiple words, which would make setenv complain, because the value is supposed to be a string in the form of one word. Putting the `command substitution` in "double quotes" changes things slightly--now it only changes newlines into word delimiters, leaving blanks and tabs untouched. That still winds up giving you multiple words if you have multiple lines. You can assign it to a variable first: % set exinit=( "`cat ~/.myexrc`" ) % setenv EXINIT "$exinit" and you won't get any complaints, but the EXINIT string won't have any newlines in it where your lines are supposed to break, an ex probably won't like that. Moral: `command substitution` in csh is fundamentally different than in sh. That observation led me to try the following, and it works fine. Just don't tell me it's ugly. I know it's ugly. In fact, if you say it was my idea I'll deny it. :-) (I'd welcome a better idea!) if ! ${?EXINIT} exec sh -c 'export EXINIT;EXINIT=`cat ${HOME}/myexrc`;exec csh' (Yuck.) The test, of course, is needed to prevent an infinite loop. Here's hoping you find a better idea and don't have to use this! -- Chap Flack Their tanks will rust. Our songs will last. chap@art-sy.detroit.mi.us -Mikos Theodorakis Nothing I say represents Appropriate Roles for Technology unless I say it does.