所以,我真的很喜欢Fish --但是我需要一些脚本方面的帮助。尤其是找到正在运行的脚本的路径。
以下是BASH Getting the source directory of a Bash script from within的解决方案
有人能帮我找到鱼的等价物吗?
发布于 2022-08-31 12:52:34
由于readlink -m在macOS上不存在,
DIR=dirname (realpath (status -f))
同时工作在macOS和Linux上。
该解决方案还可以在.sh文件甚至命令行中工作。
发布于 2013-10-30 04:01:41
status --current-filename将输出到当前正在执行的脚本的路径。
有关status命令的更多信息,可以运行man status或在http://fishshell.com/docs/current/commands.html#status上查看文档。
发布于 2015-12-05 10:37:17
在鱼壳里,
set DIR (cd (dirname (status -f)); and pwd) 是与BASH one衬垫等效的
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"在Can a Bash script tell what directory it's stored in?中提到过。
注:鱼壳将cd进入该dir,并停留在那里。Bash将cd,但它将保留在子命令中。
https://stackoverflow.com/questions/19672673
复制相似问题