LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris
User Name
Password
Solaris / OpenSolaris This forum is for the discussion of Solaris and OpenSolaris.
General Sun, SunOS and Sparc related questions also go here.

Notices



Reply
 
Search this Thread
Old 06-10-2008, 09:08 AM   #1
student04
Member
 
Registered: Jan 2004
Location: Georgia
Distribution: OS X, CentOS
Posts: 669

Rep: Reputation: 34
Question $SHELL does not reflect current shell


On both Solaris 8 and 10 I have the following:

Code:
user@computer>uname -a
SunOS computer 5.8 Generic_117350-39 sun4u sparc SUNW,Ultra-60
user@computer>echo $SHELL
/bin/csh
user@computer>which bash
/usr/bin/bash
user@computer>/usr/bin/bash
bash-2.03$ echo $SHELL
/bin/csh
bash-2.03$
bash-2.03$ ps -ef | grep user
user 22458 21665  0 09:01:44 pts/8    0:00 /usr/bin/bash
user 22475 22458  0 09:03:18 pts/8    0:00 grep user
user 21665 21663  0 08:29:38 pts/8    0:00 -csh
bash-2.03$
Why does this variable not update? How am I supposed to determine which shell I am running without visually seeing "bash" in the prompt (for all I know the prompt could be modified in some configuration file to look like that of a csh shell, using the "%" character).

-AM
 
Old 06-10-2008, 10:30 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
According to the BASH manual page
Code:
SHELL  The full pathname to the shell is kept in this environment variable. If it is not set when the
       shell starts, bash assigns to it the full pathname of the current userís login shell.
I don't know how to force the shell to set the SHELL variable upon invocation, but a unique method to determine the current shell is
Code:
echo $0
if the current shell is the login shell you will get something like -csh (that is if the first character of $0 is -, it is a login shell), otherwise you will get the full pathname of the current shell.
 
1 members found this post helpful.
Old 06-10-2008, 12:27 PM   #3
student04
Member
 
Registered: Jan 2004
Location: Georgia
Distribution: OS X, CentOS
Posts: 669

Original Poster
Rep: Reputation: 34
Ah, that's interesting. See, I've relied on the value set in this variable to determine what shell I was running. Now that it's not consistent, I'm confused.

When I run the echo command from within my login shell I get the following:
Code:
user@computer>echo $0
No file for $0
But, invoking bash beforehand it tells me what I have correctly:
Code:
user@computer>/usr/bin/bash
bash-2.03$ echo $0
/usr/bin/bash
bash-2.03$
So even though this variable is incorrect I can assume that when I run 'bash' I am in the BASH shell? A silly question, but having made this assumption in the past that's what I looked at... Oh and I am using telnet not ssh if that makes a difference (for reasons I have no authority over).

Thanks,
AM
 
Old 06-10-2008, 12:59 PM   #4
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Yes, sorry. The C-shell is an exception to the echo $0 method. A more portable way is
Code:
ps -p $$ -o comm=
this prints out the command associated to the process ID of the current shell. As you probably know, the special variable $$ holds the process ID of the script in which it appears. For interactive shells it is the process ID of the shell itself. Also note that the equal sign at the end of the output format specification is meant to suppress the header of the ps output. I tested on Solaris 5.8 and it works.
 
1 members found this post helpful.
Old 06-10-2008, 02:22 PM   #5
student04
Member
 
Registered: Jan 2004
Location: Georgia
Distribution: OS X, CentOS
Posts: 669

Original Poster
Rep: Reputation: 34
Thanks. I learn new things everyday.

-AM
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
How to check if the current shell is where I logged in? anupamsr Linux - Newbie 7 02-13-2008 04:15 PM
Determining current shell subu_s Programming 11 01-04-2005 08:10 AM
Set the Xterm title to reflect the current time ! Bonch Linux - Newbie 11 10-25-2004 05:50 PM
How to know what is the current (not initial) shell? rytrom Linux - Newbie 5 09-15-2004 02:17 PM
Finding information about the current shell atirya_yodha Linux - Newbie 3 03-18-2004 02:30 PM


All times are GMT -5. The time now is 02:37 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration