LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   bash shell parameters (https://www.linuxquestions.org/questions/programming-9/bash-shell-parameters-443608/)

jayeola 05-10-2006 05:38 PM

bash shell parameters
 
You can use the command ` echo $SHELL` to determine user's or system shell. I came across this today:-
echo ${0}
and that produces the same thing. I've checked with man bash but I've not seen (or noticed) that use of parameters are there any docs that mention this use?

taylor_venable 05-10-2006 06:14 PM

Just like the positional variables $1, $2, ... represent argument 1, argument 2, ... the variable $0 represents argument 0, which in Unix is the path used to execute the current process.

gkiagia 05-12-2006 03:35 AM

So, if you excecute `echo $0` in a terminal, it will probably show you the name of the shell, because the shell is the current process. I am not sure but I will try it. This will probably not apply in a shell script.

ioerror 05-12-2006 10:17 AM

From bash man page:

Code:

0      Expands to the name of the shell or shell script. This is set at shell initialization.
      If bash is invoked with a file of commands, $0 is set to thename of that file. If bash
      is started with the -c option, then $0 is set to the first argument after the string to
      be executed, if one is present. Otherwise, it is set to the file name used to invoke bash,
      as given by argument zero.


gkiagia 05-15-2006 10:29 AM

Well it partially works.

In konsole:
#echo $0
/bin/bash

In xterm:
#echo $0
bash

In yakuake
#echo $0
-l

The last was probably because:
Quote:

If bash is started with the -c option, then $0 is set to the first argument after the string to be executed, if one is present.
So, you cannot be sure that `echo $0` returns the shell name.


All times are GMT -5. The time now is 04:41 PM.