如何在fish shell脚本中获取程序名称?

use*_*787 9 shell fish

在bash中,如在ruby中,程序名称由$ 0给出.什么是鱼?如果必须,我可以做以下事情:

set PROGRAM (ps --no-header -o args -p %self | egrep -o '\S+')[2]
Run Code Online (Sandbox Code Playgroud)

但我确定程序名称必须已在某处可用.我也可以在每个程序的存根中将变量中的程序名设置,但是存在维护问题.

ter*_*rje 16

要获得与命令相同的结果,它是您要查找的脚本文件名.

此信息不存储在变量中,但您可以通过查询获得此信息status.

basename (status -f)      # The name of the file
status -f                 # The full path of the file
Run Code Online (Sandbox Code Playgroud)

更多信息:http: //fishhell.com/docs/2.0/commands.html#status


Édo*_*pez 5

fish 3.x

status current-command
Run Code Online (Sandbox Code Playgroud)

请参阅文档的弃用部分3.0

fish 2.x

用于$_程序名称。

请参阅文档的可编程标题部分2.0