Learning_the_bash_Shell_Third_Edition 9/n

Advanced Examples: pushd and popd

 

Task 4-8

 

The functions pushd and popd implement a stack of directories that enable you to move
to another directory temporarily and have the shell remember where you were. Imple-
ment them as shell functions.

 

pushd ( )
{
dirname=$1
DIR_STACK="$dirname ${DIR_STACK:-$PWD' '}"
cd ${dirname:?"missing directory name."}
echo "$DIR_STACK"
}
popd ( )
{
DIR_STACK=${DIR_STACK#* }
cd ${DIR_STACK%% *}
echo "$PWD"
}

  

posted @ 2021-03-04 10:10  碧水东流至此回  阅读(36)  评论(0编辑  收藏  举报