csh setenv with `cat ...`

j chapman flack chap at art-sy.detroit.mi.us
Tue Apr 30 10:45:14 AEST 1991


In article <6291 at beryl12.UUCP> mostek at 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 at art-sy.detroit.mi.us                                   -Mikos Theodorakis

Nothing I say represents Appropriate Roles for Technology unless I say it does.



More information about the Comp.unix.shell mailing list