linux脚本执行方式的不同
路径如下
/root/test.sh
脚本内容如下
#!/bin/bash
echo $0
echo $(dirname "$0")
echo $(pwd)
filepath=$(cd "$(dirname "$0")"; pwd)
echo $filepath
二级目录名字为two,(表格里应该为两个点,markdown文档格式问题)
输出结果\执行方式 | sh test.sh | /root/test.sh | 进入二级目录后进行…/test.sh |
---|---|---|---|
$0 | test.sh | /root/test.sh | …/test.sh |
$(dirname “$0”) | . | /root | … |
$(pwd) | /root | /root | /root/two |
$filepath | /root | /root | /root |