Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site proper.UUCP Path: utzoo!linus!decvax!decwrl!amd70!dual!proper!gam From: gam@proper.UUCP (Gordon Moffett) Newsgroups: net.unix Subject: New uses for csh Message-ID: <1403@proper.UUCP> Date: Sat, 23-Jun-84 23:16:13 EDT Article-I.D.: proper.1403 Posted: Sat Jun 23 23:16:13 1984 Date-Received: Wed, 27-Jun-84 03:22:25 EDT Organization: Proper UNIX, Oakland, CA Lines: 60 Keywords: csh,source,alias It was begining to frustrate me that the csh ``alias'' command accepted only one-line definitions; it is impossible to have an alias that uses ``if-then-else''. My solution to this problem was using a combination of ``source'' and ``alias'' allow possibly lengthy alias-type commands using more complex csh constructions. This is particularly applicable in the following examples. The UniSoft port I am using does not support the ``pushd'' and ``popd'' commands of csh, so I have implimented them thus: [in my .cshrc]: alias popd 'set argv = (\!*) ; source ~/csh/popd' alias pushd 'set argv = (\!*) ; source ~/csh/pushd' [~/csh/popd]: if (! $?_dirstack || $#_dirstack < 1) then echo "popd: Directory stack empty." else chdir $_dirstack[1] echo $_dirstack shift _dirstack endif [~/csh/pushd]: if ($#argv != 1) then echo "pushd: Arg count." else if (! $?_dirstack) set $_dirstack = () set _dirstack = (`pwd` $_dirstack) chdir $argv echo $argv $_dirstack endif The advantages to this method are: o More sophisticated (multi-line) csh constructs are allowed o Operates on the current shell (qv, chdir) o No overhead for reading .cshrc (as with an executable script) The disadvantages are: o Argv probably should be saved somewhere and restored o No ``exit'' from ``if'' statements (other than -- ech -- ``goto'') o Requires a file access [ These scripts were derived from someone else's implimentation of pushd/popd for csh's lacking them; I don't recall who that is, but thank you anyway ] [ Also do not use this as launch-point for another csh vs sh argument as it is not my intention to start one -- I shouldn't have to say this but I've been on the net for a while ... ] Comments and discussion are encouraged. -- Gordon A. Moffett { hplabs!nsc, decvax!sun!amd, ihnp4!dual } !proper!gam