开发者

how to access the directory stack from within a script?

I use the directory stack (listed with dirs, manipulated with pushd/popd) a lot in bash. I notice that when I run a script it has (its own shell probably, with) its own d.s.

Is there any way to access the d.s. in the shell that launched the script?

for instance if I want to do the same operation in all dire开发者_运维技巧ctories on the stack:

while [ $num -lt 0 ]
do
  num=`expr $num - 1`
  #TODO add operation here
  pushd +1
done

running this script just executes the same operation $num times in the current dir, because the scripts stack is empty.


You can use source to run a script in the context of your current bash process, but be aware that anything it does will affect your process - setting variables, changing dir, etc. It's equivalent to just typing the lines of the script directly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜