Question

So, I really like Fish - but I need some help with scripting. and in particular finding the path of the script being run.

Here is the solution for BASH Getting the source directory of a Bash script from within

Can anyone help me find the equivalent with fish?

Was it helpful?

Solution

status --current-filename will output the path to the currently executing script.

For more information on the status command, you can run man status or see the documentation at http://fishshell.com/docs/current/commands.html#status

OTHER TIPS

In fish shell,

set DIR (cd (dirname (status -f)); and pwd) 

is an equivalent to the BASH one liner

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

mentioned in Can a Bash script tell what directory it's stored in?.

NOTE: fish shell will cd into that dir and stay there. Bash will cd but it stays contained in subcommand.

File path

To get the full path of the script, use status --current-filename, or set FILE (status --current-filename) to declare a variable.

Directory path

To get the full path to the directory the script is stored in, use dirname (status --current-filename), or set DIR (dirname (status --current-filename)) to declare a variable.

The equivalent to this question is the following:

set DIR (dirname (status --current-filename)) is the equivalent

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top