LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-10-2006, 05:38 PM   #1
jayeola
Member
 
Registered: Dec 2005
Location: london, uk
Distribution: BLAG GNU/Linux
Posts: 58

Rep: Reputation: 15
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?
 
Old 05-10-2006, 06:14 PM   #2
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
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.
 
Old 05-12-2006, 03:35 AM   #3
gkiagia
Member
 
Registered: Oct 2003
Location: Greece
Distribution: Debian sid
Posts: 248

Rep: Reputation: 30
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.
 
Old 05-12-2006, 10:17 AM   #4
ioerror
Member
 
Registered: Sep 2005
Location: Old Blighty
Distribution: Slackware, NetBSD
Posts: 536

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

Last edited by ioerror; 05-12-2006 at 10:18 AM.
 
Old 05-15-2006, 10:29 AM   #5
gkiagia
Member
 
Registered: Oct 2003
Location: Greece
Distribution: Debian sid
Posts: 248

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

Last edited by gkiagia; 05-15-2006 at 10:30 AM.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing parameters to bash script Kamikazee Programming 4 10-01-2005 06:41 AM
shell: positional parameters... neidias Programming 1 04-04-2005 02:45 PM
Spaces in bash parameters rose_bud4201 Programming 5 03-11-2005 06:57 AM
Pass Parameters to php from bash iman00b Linux - Newbie 2 09-09-2004 05:30 PM
Passing Parameters to Bash Script mooreted Linux - Software 3 04-05-2004 09:08 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

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