Alias to change path on the fly

JB Christy vendijb at aix.aix.kingston.ibm.com
Fri Nov 9 02:58:33 AEST 1990


In article <1990Nov8.014515.13882 at cpsc.ucalgary.ca> paquette at 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. ***



More information about the Comp.unix.shell mailing list