I want to do some task in every directory in current path so I tried
for DIRECTORY in `find . -type d -maxdepth 1`
do
cd $DIRECTORY
#DO STUFF
cd ..
done
but I got a long error of no such file.
updateall.sh: line 5: cd: ./abc No such file or directory
Why ? I tried cd ./abc and it was fine.
thanks
cd ..
but rathercd -
. Instead of taking you up a level,cd -
takes you back to the previous directory, no matter where that was. Also, if you use( cd $DIRECTORY; do-stuff; )
you don't need to use a finalcd
at all as the current directory gets restored when you return from the( ... )
.pushd
andpopd
- and they don't work inksh
(or other non-bash shells) as far as I know. Those commands are handy though - when I used to usecsh
I used them a bit.