Path: utzoo!attcan!uunet!husc6!uwvax!tank!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.unix.questions Subject: Re: Telling csh about multiple, machine-dependent libraries Keywords: csh bin libraries Message-ID: <14592@mimsy.UUCP> Date: 17 Nov 88 18:42:39 GMT References: <173@heart-of-gold> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 71 [`heart-of-gold' is not in the UUCP maps, and linus claims never to have heard of the machine, although the news path is linus!heart-of-gold!jc; what goes on here?] In article <173@heart-of-gold> jc@heart-of-gold (John M Chambers) writes: >| set mtype = bin >| if (`sun2`) set mtype = sun2 >| if (`sun3`) set mtype = sun3 >| if (`sun4`) set mtype = sun4 >| set path=(. ~/{$mtype,sh,csh,awk} /bin /usr/{ucb,etc,local,local/{$mtype,sh},bin,lib,dos,hosts,games,demo,NeWS/{bin,demo}} /etc) The proper syntax is if ( { program } ) ... The {} pair will substitute for the () pair, so you can write if { program } ... or in this case if { sun2 } set mtype = sun2 if { sun3 } set mtype = sun3 if { sun4 } set mtype = sun4 >... I've tried a few other variants, includeing such things as > sun3 && set mtype = sun3 This should work. If you have the `machine' command (and it does the right thing) you can also use switch (`machine`) case sun2: set mtype = sun2 breaksw case sun3: set mtype = sun3 breaksw case sun4: set mtype = sun4 breaksw default: echo "unknown machine type `machine`" breaksw endsw or (much simpler) set mtype = `machine` >For that matter, the above code, if taken to a machine that lacks, e.g., >a `sun4` command, bombs out and fails to read the rest of .cshrc, so this >is obviously not a general approach. This is one reason `machine` is preferable if available. csh does not have a convenient way to test the existence of a program; but you can always use a Bourne shell script instead: set mtype = `sh .get-machine` where `.get-machine' reads if (set -e; machine) >/dev/null 2>&1; then machine else echo "no \`\`machine'' command; assuming \`\`bin''" 1>&2 echo bin fi -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris