What does $0 mean ?
%> echo $0
-tcsh It returns the current shell Does it mean there exist variable named 0 ? If yes how do you list all the existing variables, %> Set does not seem to list it. Thanks, |
It contains the first word i.e. the command name, when use in a script.
Let's know that in what respect you're asking? |
Hi Shivaa,
I want to know what does it mean to the interpreter. Is there a variable named 0, Available to the shell. Thanks, p.s. - I am new to the linux world and hope asking the right question. |
Hi, $0, $1, $2 etc are shell built-in variables, and called positional parameters.
For more clarification, refer: http://www.tldp.org/LDP/abs/html/oth...html#CHILDREF2 If you simply run it from shell i.e. echo $0, it will return the name of the running process i.e. shell. And if you use it within a script, then it will store the script name itself. |
You have to be careful about applying bourne-shell syntax explanations to the c-shells. There are many things about them that are very different.
In this case, however, it's correct. The "$0" positional stores the name of the command, in the form that it was run as (i.e. if you launch the script through a symlink, it will hold the link's name). In bash, it's treated slightly differently from the rest of the parameters, in that it doesn't appear in the "$@/$*" lists, or get affected by commands like shift, but in all other respects it's just another parameter. But parameter use in the c-shell appears to be a bit different, so it may not have quite the same behavior there. It seems, for example, that csh doesn't have a "$@" variable, and you have to use "$argv" instead. There's a lot of documentation on the web about csh/tsch syntax. Just google it. (And read here for several good reasons why you should avoid using it for scripting.) http://www.grymoire.com/Unix/CshTop10.txt |
And note - the name provided is a name, this does not necessarily correspond to the file given.
As you saw, giving "echo $0" in your sell gave you the value "-tcsh". This isn't the command "tcsh". Login normally puts a "-" character in front of the users shell (as specified in /etc/passwd) file to indicate to the shell that it is an interactive shell. Under normal invocation, the parameter would have included "/bin/tcsh" (or "/usr/bin/tcsh") exactly as specified in the passwd file. But to indicate to tcsh (and most shells) it tells the command interpreter that it should take special action (processing the login configuration scripts usually) the "-" is put on the beginning of the base file name. |
All times are GMT -5. The time now is 03:55 PM. |