Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

shell

fish

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.

like image 324
user1494787 Avatar asked Jun 07 '13 03:06

user1494787


People also ask

How do I write a fish shell script?

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>.

How to get the script name in shell script?

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.

Is there any guide about how to program using fish?

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.

Is it possible to use Bash command in fish?

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.


2 Answers

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

like image 63
terje Avatar answered Dec 15 '22 10:12

terje


For fish use $_ for program name.

like image 26
jaypal singh Avatar answered Dec 15 '22 10:12

jaypal singh