Bash - 从 $PATH 打印文件的完整路径
Bash - Print the full path of a file from $PATH
假设我的 $PATH
中有 ~/scripts
并且该路径中有 script.sh
。
我可以通过直接在终端中输入 script.sh
来执行该脚本,但是如果我想在不知道脚本的基本路径(或在其中添加任何函数)的情况下打印出该脚本的完整路径怎么办脚本打印出自己的路径)?有什么好的方法吗?
在bash中,要在用户路径中定位一个文件(脚本),可以使用which
命令:(https://ss64.com/bash/which.html), but as @Jetchisel says there are better alternatives for POSIX-compliant shells; see 'which' vs 'command -v' in Bash
假设我的 $PATH
中有 ~/scripts
并且该路径中有 script.sh
。
我可以通过直接在终端中输入 script.sh
来执行该脚本,但是如果我想在不知道脚本的基本路径(或在其中添加任何函数)的情况下打印出该脚本的完整路径怎么办脚本打印出自己的路径)?有什么好的方法吗?
在bash中,要在用户路径中定位一个文件(脚本),可以使用which
命令:(https://ss64.com/bash/which.html), but as @Jetchisel says there are better alternatives for POSIX-compliant shells; see 'which' vs 'command -v' in Bash