受到这个问题的启发。
Getting the source directory of a Bash script from within
是否可能,但不需要 bash。
我正在运行 Ubuntu,在我需要 Bash 问题的公认解决方案之前,我的哈希爆炸是这样的
#!/bin/sh
我喜欢这样,有没有办法保持这种状态?
编辑:
它应该输出正确的目录,即使这样运行,
./script.sh
最佳答案
怎么样$(dirname -- "$0")
?
如果您的 shell 仅使用反引号,则为:
`dirname -- "$0"`
关于shell - shell 脚本可以告诉它在哪个目录中。没有 bashisms,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8468519/