用fish检索当前源文件的路径
在fish shell脚本中,是否可以获得shell脚本所在的路径?在 bash 中,您可以使用 BASH_SOURCE 变量来执行此操作。
In a fish shell script, is it possible to obtain the path where the shell script lives? In bash, you can use the BASH_SOURCE variable to do this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种方法是使用 status 命令。
例如。
-
啊,抱歉 - 从你的评论来看,我误解了这个问题。我以为你的意思是完全限定的路径,而不是脚本的目录。
您可以将状态结果发送到 dirname。它不像 status 那样是 Fish 的内置功能,但 Fish 倾向于尽可能多地外包此功能(请参阅 Fish 中的“极简主义法则”设计文档)。我在文档中看不到任何更好的命令,所以也许这就是我们现在能得到的最好的命令?
修改示例,将 show_filename.fish 的内容更改为:
现在您应该得到:
One way is to use the status command.
eg.
--
Ah, sorry - judging by your comment, I misread the question. I thought you meant the fully qualified path, instead of the script's directory.
You could just send the status result to dirname. It's not a built-in function of fish, like status is, but fish tends to outsource as much of this functionality as it can anyway (see "The law of minimalism", over in the fish design doc). I can't see anything better commands in the docs for this, so maybe this is as good as we can get for now?
Amending the example, change the contents of show_filename.fish to be:
Now you should get: