We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
解析:dirname $0表示脚本父目录;pwd即进入父目录后获取绝对路径;不能只执行pwd或者$0。 附注:单独执行pwd或$0的结果: +---------------------------------- /tmp/test/f1.sh: echo "pwd:" $(pwd) echo '$0: ' $0 +---------------------------------- Test:/ # bash /tmp/test/f1.sh pwd: / $0: /tmp/test/f1.sh +---------------------------------- Test:/tmp # bash /tmp/test/f1.sh pwd: /tmp $0: /tmp/test/f1.sh +---------------------------------- Test:/tmp/test # bash /tmp/test/f1.sh pwd: /tmp/test $0: /tmp/test/f1.sh +---------------------------------- Test:/tmp/test # bash f1.sh pwd: /tmp/test $0: f1.sh
The text was updated successfully, but these errors were encountered:
No branches or pull requests
绝对路径(不含fileName):$(cd $(dirname $0);pwd)
解析:dirname $0表示脚本父目录;pwd即进入父目录后获取绝对路径;不能只执行pwd或者$0。
附注:单独执行pwd或$0的结果:
+----------------------------------
/tmp/test/f1.sh:
echo "pwd:" $(pwd)
echo '$0: ' $0
+----------------------------------
Test:/ # bash /tmp/test/f1.sh
pwd: /
$0: /tmp/test/f1.sh
+----------------------------------
Test:/tmp # bash /tmp/test/f1.sh
pwd: /tmp
$0: /tmp/test/f1.sh
+----------------------------------
Test:/tmp/test # bash /tmp/test/f1.sh
pwd: /tmp/test
$0: /tmp/test/f1.sh
+----------------------------------
Test:/tmp/test # bash f1.sh
pwd: /tmp/test
$0: f1.sh
The text was updated successfully, but these errors were encountered: