Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!mips!apple!agate!usenet From: danabu@garnet.berkeley.edu (Daniel N. Abushanab) Newsgroups: comp.unix.shell Subject: Help with this script Message-ID: <1991Apr9.164257.9128@agate.berkeley.edu> Date: 9 Apr 91 16:42:57 GMT Sender: usenet@agate.berkeley.edu (USENET Administrator) Organization: University of California, Berkeley Lines: 45 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@scorpio.berkeley.edu Mechanical Engineering Department phone: (415) 642-5109 ---------------------------------------------------------------------------- Daniel N. Abushanab University of California, Berkeley E-mail: danabu@garnet.berkeley.edu Mechanical Engineering Department phone: (415) 642-5109