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.
Learn how to write fish shell scripts by example. To be able to run fish scripts from your terminal, you have to do two things. Add the following shebang line to the top of your script file: #!/usr/bin/env fish. Mark the file as executable using the following command: chmod +x <YOUR_FISH_SCRIPT_FILENAME>.
Now in this article I will share some tips to get the script name in shell script, get script path in bash script with examples. You can collect these values from within the script. Use the below variable within the script to get the script name from within the shell script So both our variables are giving us the script name of the executed script.
Unfortunately there is not much guides about how to program using it. That’s sad because fish has a lot of advantages over bash to write scripts: cleaner and easier to remember syntax, good variables escaping, etc.. So I decided to write a small tutorial on the subject.
That command is specific to bash so it is not usable in fish, fortunately we can use an alternative which is the Unix standard getopt command (notice the only difference is the “s”). Here is a complete example of usage of a command line arguments parsing program in fish.
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
For fish
use $_
for program name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With