Help with this script
Daniel N. Abushanab
danabu at garnet.berkeley.edu
Wed Apr 10 02:42:57 AEST 1991
Hi,
I'm trying to write a script to emulate the DOS Norton Utilities "ncd"
command. It should scan a directory tree file, find a directory that
matches a pattern inputted by the user, then exit. The following shell
accomplishes that job. Unfortunately, when the shell is exited it
returns the user to the directory from which it was called. Does anyone
have any idea about how to fix this? Any help is appreciated, please
respond by e-mail and I will post solution here.
Shell script follows:
#This is a shell script to scan your directory structure and change
#to a directory matching a pattern you input. To use type "acd
#pattern". "acd ..." rebuilds the tree structure.
#This changes the directory, but upon exiting the shell the
#program returns to its starting directory. I want it to
#stay where it is upon exiting.
if (test $1) then
if (test $1 = "...") then
echo "creating tree file..."
/bin/ls -R $HOME | grep : | awk -F: '{print $1}' > $HOME/tree.abu
exit
fi
DIRECTORY=`grep "$HOME.*/$1" $HOME/tree.abu`
FIRST=`echo $DIRECTORY | awk '{print $1}'`
if (test $FIRST) then
echo "Changing to $FIRST"
cd $FIRST
else echo "Could not find $1."
fi
else echo "You must include a directory."
fi
----------------------------------------------------------------------------
Daniel N. Abushanab University of California, Berkeley
E-mail: danabu at scorpio.berkeley.edu Mechanical Engineering Department
phone: (415) 642-5109
----------------------------------------------------------------------------
Daniel N. Abushanab University of California, Berkeley
E-mail: danabu at garnet.berkeley.edu Mechanical Engineering Department
phone: (415) 642-5109
More information about the Comp.unix.shell
mailing list