Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.)
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.