Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site rlgvax.UUCP Path: utzoo!watmath!clyde!cbosgd!cbdkc1!desoto!packard!hoxna!houxm!mhuxr!ulysses!allegra!mit-eddie!godot!harvard!seismo!rlgvax!peter From: peter@rlgvax.UUCP (Peter Klosky) Newsgroups: net.unix,net.unix-wizards Subject: Re: arguments for command file ( long, pedantic response ) Message-ID: <314@rlgvax.UUCP> Date: Fri, 21-Dec-84 15:27:54 EST Article-I.D.: rlgvax.314 Posted: Fri Dec 21 15:27:54 1984 Date-Received: Sun, 23-Dec-84 00:43:26 EST References: <2650@dartvax.UUCP> Distribution: net Organization: CCI Office Systems Group, Reston, VA Lines: 44 Xref: watmath net.unix:3154 net.unix-wizards:11186 > > I am facing a problem writing a command file. I would like this file > to be run with an argument supplied. The command it executes is cd. > cd $1 > I print the pwd in the command file and it prints the expected one. > On using the command pwd outside the command file I find that the > change in the directory has not been made. You do not say which shell you are using, as in sh or csh, but at any rate the problem is that your command file is probably being interpreted by a subprocess, and while you have managed to get the working directory of the subprocess changed, this does not change your parent's current working directory. You have similar trouble if you try to change an environment variable in a subshell. This is a feature, btw, not a bug. A solution is to have the command file read by the current shell instead of in a subshell. With the Bourne shell (sh) you can "dot" the file as in . cd_command_file with the Joy shell (csh), you can alias "cd" to source a command file which will perform your stuff then chdir to the argument. Here is a "cd" alias and associated command file which will perform just like cd, and also maintain a "trail of bread crumbs" which you can follow back via the "." alias also included. Also you can switch between two directories via the "sw" alias. PART A: ( aliases for .login ) set l='(' m=')' alias cd 'set arg=\!*;source ~/.pushd;unset arg;set prompt="${l}\\!${m} ${cwd}: "' alias sw 'pushd >& /dev/null;set prompt="${l}\\!${m} ${cwd}: "' alias . 'popd > /dev/null ;set prompt="${l}\\!${m} ${cwd}: "' set prompt="${l}\!${m} ${cwd}: " PART B: ( command file sourced by cd aliase; ~/.pushd ) if ( "$arg" == "" ) then pushd ~ >/dev/null else pushd $arg >/dev/null endif