-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
绝对路径(不含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
Metadata
Metadata
Assignees
Labels
No labels