当我以普通用户身份运行以下命令时,一切正常:
$(dirname `readlink -f $0`)
Run Code Online (Sandbox Code Playgroud)
但是在我切换到root后,出现了以下错误:
readlink: invalid option -- 'b'
Try `readlink --help' for more information.
dirname: missing operand
Try `dirname --help' for more information.
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?我在本地 Fedora 16 和 Amazon EC2 上尝试过,它们都运行 bash shell。
编辑插图。
很抱歉我没有在这里进一步说明这个问题。这是场景:
使用普通用户帐户:
$ pwd
/home/myuser
$ export MY_DIR=$(dirname `readlink -f $0`)
$ echo MY_DIR
/home/myuser
Run Code Online (Sandbox Code Playgroud)
使用根:
# pwd
/root
# export ROOT_DIR=$(dirname `readlink -f $0`)
readlink: invalid option -- 'b'
Try `readlink --help' for more information.
dirname: missing operand
Try `dirname --help' for more information.
# export ROOT_DIR=echo $(dirname `readlink -f -- $0`)
# echo $ROOT_DIR
/root
Run Code Online (Sandbox Code Playgroud)
enz*_*tib 18
这应该与用户登录 shell 中的错误相同,因为在登录 shell 中,0
shell 参数扩展为当前进程的名称,给出-bash
了表示登录 shell 的减号。您现在可以看到-b
错误的来源。
试试吧
echo "$( dirname "$(readlink -f -- "$0")" )"
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
17340 次 |
最近记录: |