🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.unix.shell
9 messages
9 total messages Started by Trevor Paquette Thu, 08 Nov 1990 01:45
Alias to change path on the fly
#1704
Author: Trevor Paquette
Date: Thu, 08 Nov 1990 01:45
41 lines
2439 bytes
 Quick and I hope a fairly simple question. We have some programs
that must be able to take advantage of two co-processors on a sun.
The executables are name prog_host (no coprocessor), prog_sc (Supercard
coprocessor) and prog_qc (Quickcard coprocessor).
 Each executable is in a seperate directory. I want to be able to change
my path on the fly to get at a certain executable. This is what I have
done so far.
Let's say my path is set as :
(. /usr/ucb /bin /usr/bin /usr/local/bin /home/insight/sparc/bin/itahost)
                                                                 *******
itahost contains all the prog_host executables.
itaqc   contains all the prog_qc executables.
itasc   contains all the prog_sc executables.

I have come up with the following aliases to change which directory I will use

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/'

 These aliases of course only ECHO what the command to change the path should 
be.
To actually execute the command we must put some ` around the command.

 So the new aliases should be:
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

 What am I doing wrong???????????

  Trev
-- 
______________________________________/Through the darkness, the future past,
Trevor Paquette  ICBM:51'03"N/114'05"W|The magician longs to see.
{ubc-cs,utai,alberta}!calgary!paquette|One chants out, between two worlds,
paquette@cpsc.ucalgary.ca             |"Fire, walk with me."
Re: Alias to change path on the fly
#1708
Author: JB Christy
Date: Thu, 08 Nov 1990 15:58
35 lines
2289 bytes
In article <1990Nov8.014515.13882@cpsc.ucalgary.ca> paquette@cs-sun-fsa.cpsc.ucalgary.ca (Trevor Paquette) writes:
}I have come up with the following aliases to change which directory I will use
}
}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/'
}
} These aliases of course only ECHO what the command to change the path should 
}be.
}To actually execute the command we must put some ` around the command.
}
} So the new aliases should be:
}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

csh parses commands before it does variable and command substitutions, so
by the time it's figured out the output of your echo, it's no longer
looking for a command.  You have two choices.  You can explicitly tell csh
to parse the command after substitution (i.e. to 'eval'uate the output of
your echo -- see the csh man page under the 'eval' command):

alias sc 'eval `echo set path=\($path\)|sed s/itaqc/itasc/  |sed s/itahost/itasc/`'

Or, more directly, you can just set the path to the proper thing yourself:

alias sc 'set path=`echo \($path\)|sed s/itaqc/itasc/  |sed s/itahost/itasc/`'
-- 
JB (Beth) Christy			"She was a suicide blonde --
Resource One, Inc.			 dyed by her own hand."

*** I speak only for myself, and half the time I get that wrong. ***
Re: Alias to change path on the fly
#1707
Author: 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
Re: Alias to change path on the fly
#1705
Author: John P. Eisenmenger
Date: Thu, 08 Nov 1990 23:02
18 lines
1343 bytes
From article <1990Nov8.014515.13882@cpsc.ucalgary.ca>, by paquette@cs-sun-fsa.cpsc.ucalgary.ca (Trevor Paquette):
>  So the new aliases should be:
> 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
> 
>  What am I doing wrong???????????

try these:

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

-John
Re: Alias to change path on the fly
#1706
Author: Paul Chamberlain
Date: Fri, 09 Nov 1990 19:36
17 lines
1311 bytes
In article <1990Nov8.014515.13882@cpsc.ucalgary.ca> paquette@cs-sun-fsa.cpsc.ucalgary.ca (Trevor Paquette) writes:
>I have come up with the following aliases to change which directory I will use
>...
>alias host '`echo set path=\($path\)|sed s/itaqc/itahost/|sed s/itasc/itahost/`'
>...

Untested but much more likely to succeed alias follows:

alias host 'set path=(`echo $path|sed s/itaqc/itahost/|sed s/itasc/itahost/`)'
...

But, if I were you, I'd do something like this (which I even tested):

alias host 'set path=(`echo $path|sed "s/ita[a-z]*/itahost/"`)'

Paul Chamberlain | I do NOT represent IBM.     tif@doorstop, sc30661 at ausvm6
512/838-7008     | ...!cs.utexas.edu!ibmchs!auschs!doorstop.austin.ibm.com!tif
Re: Alias to change path on the fly - ALTERNATIVE
#1745
Author: Paul Davey
Date: Sat, 10 Nov 1990 15:41
34 lines
2037 bytes
In article <1990Nov8.014515.13882@cpsc.ucalgary.ca> paquette@cs-sun-fsa.cpsc.ucalgary.ca (Trevor Paquette) writes:

->    Quick and I hope a fairly simple question. We have some programs
->   that must be able to take advantage of two co-processors on a sun.
->   The executables are name prog_host (no coprocessor), prog_sc (Supercard
->   coprocessor) and prog_qc (Quickcard coprocessor).
->    Each executable is in a seperate directory. I want to be able to change
->   my path on the fly to get at a certain executable. This is what I have
->   done so far.
->   Let's say my path is set as :
->   (. /usr/ucb /bin /usr/bin /usr/local/bin /home/insight/sparc/bin/itahost)
...

lots of mucking around with sed deleted...

As an alternative solution I'd use a symbolic link to the bin and
delete it and recreate it as required.

if your three bins are: /home/insight/sparc/bin/itahost
			/home/insight/sparc/bin/itaqc
			/home/insight/sparc/bin/itasc

set path = (. /usr/ucb /bin /usr/bin /usr/local/bin ~/itabin)

alias host  'rm -f  ~/itabin ; ln -s /home/insight/sparc/bin/itahost'
alias qc    'rm -f  ~/itabin ; ln -s /home/insight/sparc/bin/itaqc'
alias sc    'rm -f  ~/itabin ; ln -s /home/insight/sparc/bin/itasc'

(you don't need to rehash, at least not on my machine)
--
 Regards,			 pd@x.co.uk          IXI Limited
	Paul Davey		 pd@ixi.uucp         62-74 Burleigh St.
				 ...!uunet!ixi!pd    Cambridge  U.K.
 "These are interesting times"   +44 223 462 131     CB1  1OJ      
Re: Alias to change path on the fly - ALTERNATIVE
#1746
Author: Richard L. Goerwitz
Date: Sun, 11 Nov 1990 19:32
8 lines
831 bytes
In <PAUL.90Nov10154152@cheshire.ixi.uucp> paul@ixi.uucp (Paul Davey) writes:

>As an alternative solution I'd use a symbolic link to the bin and
>delete it and recreate it as required.

Ln -s isn't portable, as I'm sure you know.  Hmmm.

-Richard
Re: Alias to change path on the fly - ALTERNATIVE
#1785
Author: deraadt
Date: Wed, 14 Nov 1990 06:42
27 lines
1784 bytes
In article <1990Nov8.014515.13882@cpsc.ucalgary.ca> paquette@cpsc.ucalgary.ca:
>  Quick and I hope a fairly simple question. We have some programs
> that must be able to take advantage of two co-processors on a sun.
> The executables are name prog_host (no coprocessor), prog_sc (Supercard
> coprocessor) and prog_qc (Quickcard coprocessor).
>  Each executable is in a seperate directory. I want to be able to change
> my path on the fly to get at a certain executable. This is what I have
> done so far.
> Let's say my path is set as :
> (. /usr/ucb /bin /usr/bin /usr/local/bin /home/insight/sparc/bin/itahost)

Create a shell script that determines the situation, and then runs the
correct one.

file ~/bin/g88 contains:
	exec ~me/bin/`arch`/$0 $*

and there are directories in ~/bin called sun3, sun4, etc.
This can be extended to support more than just `arch` if desired.

Or whatever else is required to do the job.
This along the lines of how Framemaker is shipped.
 <tdr.
--

SunOS 4.0.3: /usr/include/vm/as.h, Line 44      | Theo de Raadt
Is it a typo? Should the '_'  be an 's'?? :-)   | deraadt@cpsc.ucalgary.ca
Re: Alias to change path on the fly - ALTERNATIVE
#1743
Author: The Grey Wolf
Date: Thu, 15 Nov 1990 01:13
19 lines
1214 bytes
In article <1990Nov11.193202.6051@midway.uchicago.edu> goer@quads.uchicago.edu (Richard L. Goerwitz) writes:
>In <PAUL.90Nov10154152@cheshire.ixi.uucp> paul@ixi.uucp (Paul Davey) writes:
>
>>As an alternative solution I'd use a symbolic link to the bin and
>>delete it and recreate it as required.
>
>Ln -s isn't portable, as I'm sure you know.  Hmmm.
>
>-Richard

Symlinks *not PORTABLE*???? on a SUN?  You must be kidding.  Even SVR4
supports symlinks these days.


-- 
"This is *not* going to work!"
				"Well, why didn't you say so before?"
"I *did* say so before!"
...!{ucbvax,acad,uunet,amdahl,pyramid}!unisoft!greywolf
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads