0

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

cd - 1>&2 >/dev/null

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

虽然完全相同的逻辑适用于 AIX 和 RHEL,但它显然不适用于 Solaris,我得到的错误暗示没有以前的目录可以返回,而实际上脚本已将目录更改为/etc/opt/esmsym.

如何在 Solaris 上进行这项工作?

你有替代方案吗?

4

1 回答 1

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.
于 2013-07-31T18:42:06.247 回答