Shell script help needed
James Logan III
logan at vsedev.VSE.COM
Wed Nov 23 09:47:10 AEST 1988
In article <1872 at loral.UUCP> jlh at 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 </dev/tty;
fi;
done <$DIRFILE;
echo "\07\nDone.\07";
-------------- CUT HERE ------------------
--
Jim Logan logan at vsedev.vse.com
(703) 892-0002 uucp: ..!uunet!vsedev!logan
inet: logan%vsedev.vse.com at uunet.uu.net
More information about the Comp.unix.wizards
mailing list