LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-01-2013, 11:02 PM   #1
.product
LQ Newbie
 
Registered: Dec 2012
Location: India
Distribution: Ubuntu
Posts: 8

Rep: Reputation: Disabled
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,
 
Old 01-01-2013, 11:46 PM   #2
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
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?
 
Old 01-01-2013, 11:55 PM   #3
.product
LQ Newbie
 
Registered: Dec 2012
Location: India
Distribution: Ubuntu
Posts: 8

Original Poster
Rep: Reputation: Disabled
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.
 
Old 01-02-2013, 12:26 AM   #4
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
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.
 
1 members found this post helpful.
Old 01-02-2013, 01:02 AM   #5
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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
 
Old 01-02-2013, 09:12 AM   #6
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration