🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.shell
Article #1707

Re: Alias to change path on the fly

#1707
From: Jonathan I. Kamens
Date: Thu, 08 Nov 1990 21:31
45 lines
2816 bytes
  (Note the Followup-To, which probably should have been set to something in
the original posting.  I was all set to flame at the poster for posting a
question to comp.unix.internals that doesn't have anything at all to do with
Unix internals, and then I realized that he posted it to comp.unix.wizards,
which is aliased to comp.unix.internals, at least at my site. :-)

In article <1990Nov8.014515.13882@cpsc.ucalgary.ca>, paquette@cs-sun-fsa.cpsc.ucalgary.ca (Trevor Paquette) writes:
|> alias host '`echo set path=\($path\)|sed s/itaqc/itahost/|sed s/itasc/itahost/`'
|> alias qc   '`echo set path=\($path\)|sed s/itahost/itaqc/|sed s/itasc/itaqc/  `'
|> alias sc   '`echo set path=\($path\)|sed s/itaqc/itasc/  |sed s/itahost/itasc/`'
|>   But these new aliases give me the following error: 
|> 
|> `echo set path=\($path\)|sed s/itaqc/itahost/|sed s/itasc/itahost/`: Ambiguous

  The C-shell has a problem (discussed several times in comp.unix.shell
recently) with deciding exactly when the output of a backquote substitution
should be expanded into multiple words.  Another example of this is that typing

    kill `cat file-with-list-of-pids-in-it`

won't work because the list of pids will all be treated as one word.  This is
only a problem with the "kill" shell built-in, though, so if you substitute
"/bin/kill" for "kill", it works fine.  The problem you are having is another
manifestation of this.

  The way to get around it is to change your aliases.  For example;

    alias host 'set path= (`echo $path|sed -e s/itaqc/itahost/g -e \\\
      s/itasc/itahost/g`)'

Note that this has the added advantages of using only one invocation of sed
instead of two, and of replacing itasc and itaqc whereever they appear in your
path, not just the first time.

  You could also solve the problem by using eval instead of backquotes,
although you might have to make some minor changes to your aliases in that
case too.  Figuring out how to do this is left as an exercise to the reader
:-).

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik@Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8085			      Home: 617-782-0710
Technical Details
Message-ID: <1990Nov8.213125.1544@athena.mit.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!ucsd!ucbvax!bloom-beacon!athena.mit.edu!jik
References: <1990Nov8.014515.13882@cpsc.ucalgary.ca>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!ucsd!ucbvax!bloom-beacon!athena.mit.edu!jik
From: jik@athena.mit.edu (Jonathan I. Kamens)
Newsgroups: comp.unix.shell,comp.unix.wizards,comp.unix.programmer
Subject: Re: Alias to change path on the fly
Message-ID: <1990Nov8.213125.1544@athena.mit.edu>
Date: 8 Nov 90 21:31:25 GMT
References: <1990Nov8.014515.13882@cpsc.ucalgary.ca>
Sender: daemon@athena.mit.edu (Mr Background)
Reply-To: jik@athena.mit.edu (Jonathan I. Kamens)
Followup-To: comp.unix.shell
Organization: Massachusetts Institute of Technology
Lines: 45