a.sh
path=xxx
经常使用source xxpath/a.sh 调用a.sh
在a.sh中如何获取自身所在文件夹路径呢?
1
eamars 2015 年 1 月 13 日
cd "$(dirname "$0")"
|
2
gamecreating 2015 年 1 月 13 日
pwd
|
4
eamars 2015 年 1 月 13 日
|
5
bellchu 2015 年 1 月 13 日
realpath
|
12
Beebird 2015 年 1 月 13 日
#!/bin/env bash
... LOCATION=$(pwd) #echo $LOCATION ... |
14
lululau 2015 年 1 月 13 日
|
18
Beebird 2015 年 1 月 13 日
@otmb 试了可以啊,不论是source还是直接运行。
cat testpwd.sh #!/bin/env bash LOCATION=$(pwd) echo $LOCATION $ source testpwd.sh /home/lzhao/tmp |
19
HowardMei 2015 年 1 月 13 日
sh和bash下面source和直接执行需要的判断参数不同,从"$_" "$0" "$BASH_SOURCE"三个里面找,如果是curl或cat script.sh | bash方式,
这三个都没用,参考: https://github.com/HowardMei/shbin/blob/master/shbin/shsrc |
20
KentY 2015 年 1 月 13 日
|