How to get the program name in a fish shell script?

﹥>﹥吖頭↗ 提交于 2019-12-08 15:59:02

问题


In bash, as in ruby, the program name is given by $0. What is it in fish? I can do the following if I have to:

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

But I'm sure the program name must be already available somewhere. I could also set the program name in variable at the stub of each program, but that has maintenance problems.


回答1:


To get the same result as your command, it is the script filename you are looking for.

This information is not stored in a variable, but you get this by querying status.

basename (status -f)      # The name of the file
status -f                 # The full path of the file

More information: http://fishshell.com/docs/2.0/commands.html#status




回答2:


For fish use $_ for program name.




回答3:


fish 3.x

status current-command

See Deprecations section of the 3.0 documentation.

fish 2.x

Use $_ for program name.

See Programmable title section of the 2.0 documentation.



来源:https://stackoverflow.com/questions/16975804/how-to-get-the-program-name-in-a-fish-shell-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!