我尝试了以下但没有奏效。
dir=$pwd
echo $dir
/bin/env/####/ --id --edition dir- $dir
我想将当前工作目录粘贴到上面的脚本中。
最佳答案
当前目录已经在一个名为 PWD
的变量中,它是 automatically set by the shell :
echo "$PWD"
你也可以:
dir=$(pwd)
echo "$dir"
或者您可以在脚本中使用这些而不存储在其他变量中:
/bin/env/####/ --id --edition-dir "$PWD"
/bin/env/####/ --id --edition-dir "$(pwd)"
供您引用:每次更改目录时,无论是在交互式 shell 还是脚本中,shell 都会设置
PWD
的值。当前目录的变量,以及OLDPWD
的值到上一个目录。嗯,通常。如 @WilliamPursell指出,
OLDPWD
不是标准的,所以它可能不适用于所有 shell。
关于shell - 如何在 Unix shell 中将 pwd 定义为变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20839678/