Path: utzoo!attcan!uunet!vsedev!logan From: logan@vsedev.VSE.COM (James Logan III) Newsgroups: comp.unix.wizards Subject: Re: Shell script help needed Keywords: Suspend a foreach() loop? Message-ID: <1248@vsedev.VSE.COM> Date: 22 Nov 88 23:47:10 GMT References: <1872@loral.UUCP> Reply-To: logan@vsedev.VSE.COM (James Logan III) Organization: VSE Software Development Lab Lines: 66 In article <1872@loral.UUCP> jlh@loral.UUCP (Physically Pffft) writes: >Our application has it's source code in 9 directories, and I find that >often I need to make similar changes in all 9 directories. Manually >cd'ing into each directory is error prone, some are skipped and others >are entered more than once. I'd like to write a shell script to automate >this that would act as follows: > >1. Enter all the directory names into a file (only need to do once) >2. Invoke the script, it reads the first directory from the file and > cd's into it. It then suspends itself. >3. I do what I need to. >4. I enter 'next' or something to wake up the script, it reads the next > directory from the file and cd's into it. Steps 2-4 are done for > all directories. > >My problem is I don't know how to suspend a shell script like this, and then >have it continue where it left off. My only idea is to create a new shell >('/bin/sh'), but I think this would be slower than snail snot. Anyone >have any ideas? Thanks. Invoking another instance of /bin/sh should not be slow since the text segment of /bin/sh is shared by more than one process. I wrote you the following shell script that runs VERY quickly on my system. It will handle the requirements you posted. Just type "^D" (control-D) or "exit" to go to the next directory. -Jim ------------ CUT HERE -------------- # autocd.sh James Logan Tue Nov 22 18:27:16 EST 1988 # Read a list of directories from $DIRFILE and invoke # an interactive shell for each directory. # # Set DIRFILE if not already set to something else in the # user's environment. # DIRFILE=${DIRFILE:-"dirs"}; if test ! -r "$DIRFILE"; then echo >&2 "$0: Cannot read '$DIRFILE'."; exit 1; fi; # # Feed the file $DIRFILE into stdin and read a line at a time. # while read DIR; do echo "\nChanging to directory '$DIR'"; if cd $DIR; then PS1="$DIR> "; export PS1; # Redirect stdin from user's tty -- it is currently # connected to $DIRFILE (inherited from the while loop). sh -i