cd - 1>& 2> / dev / null在Solaris上无法正常工作

时间:2013-07-31 18:20:38

标签: solaris

我在AIX和RHEL的脚本中使用命令:

cd - 1>&2 >/dev/null

我知道这是在尝试更改到另一个目录后返回上一个目录。

虽然完全相同的逻辑适用于AIX和RHEL,但它显然不适用于Solaris,错误是我暗示没有以前的目录可以返回,而实际上脚本已将目录更改为{ {1}}。

如何在Solaris上完成这项工作?

你有其他选择吗?

1 个答案:

答案 0 :(得分:0)

尝试跑步:

cd $OLDPWD

这应该会带你回到上一个工作目录。

或者,如果这不起作用,那么您可以尝试使用它:

export path=$(pwd)

cd ~/B/
cd $path

这会将当前路径的副本保存到$path变量,然后将当前目录更改为~/B/,然后使用$path变量返回上一个工作目录。


正如旁注,还有podppushd

pushd $(pwd)

cd /tmp

popd

取自popd(1)

pushd pushes a directory onto the directory stack. With no arguments, exchange the top two elements.

   +n
       Rotate the n’th entry to the top of the stack and cd to it.
   dir
       Push the current working directory onto the stack and change to dir.

popd pops the directory stack and cd to the new top directory. The elements of 
the directory stack are numbered from 0 starting at the top.

   +n
       Discard the n’th entry in the stack.