TorosFanny TorosFanny - 3 months ago 7x
Bash Question

How to get the path of a fish script within itself

In bash, we can get the path of a script with

. It seems that we can do that in a fish script by
according to the official document.

How ever, if I try to write a fish script like this, and run it, it will print just a newline.

echo $_

While in a reactive fish,
echo $_
will give
literately and
<command> $_
will pass "command" literately as
's argument.

I am confused about the strange behavior of
, and what it is used for.


$_ is a bit confusing, but it's not the "path to the fish script", it's the name of the current foreground job.

To get the path to the script, use status --current-filename (which will be "standard input" if launched interactively).