How to find out name of script called (“sourced”) by another script in bash?
本问题已经有最佳答案,请猛点这里访问。
Possible Duplicate:
In the bash script how do I know the script file name?
How can you access the base filename of a file you are sourcing in Bash
当使用
文件1.SH
1 2 3 | #!/bin/bash echo"from file1: $0" source file2.sh |
文件2.SH
1 2 | #!/bin/bash echo"from file2: $0" |
运行file1.sh
1 2 3 | $ ./file1.sh from file1: ./file1.sh # expected from file2: ./file1.sh # was expecting ./file2.sh |
问:我怎样才能从
将
1 2 | #!/bin/bash echo"from file2: ${BASH_SOURCE[0]}" |
注意,
如果您
如果你想知道
1 2 3 | #!/bin/bash echo"from file1: $0" ./file2.sh |
文件2.SH
1 2 | #!/bin/bash echo"from file2: $0" |