- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- What command to determine the current shell?
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-12-2003 11:32 AM
тАО02-12-2003 11:32 AM
What command to determine the current shell?
Shawn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-12-2003 11:35 AM
тАО02-12-2003 11:35 AM
Re: What command to determine the current shell?
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-12-2003 11:36 AM
тАО02-12-2003 11:36 AM
Re: What command to determine the current shell?
Your shell is set in /etc/passwd and exec'd when you login.
If you want to see what shell you are running, you can do:
echo $SHELL
[at least in ksh and POSIX sh, I'm not sure about csh].
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-12-2003 11:37 AM
тАО02-12-2003 11:37 AM
Re: What command to determine the current shell?
#echo $SHELL
Rgds,
Jeff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-12-2003 11:37 AM
тАО02-12-2003 11:37 AM
Re: What command to determine the current shell?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-12-2003 11:38 AM
тАО02-12-2003 11:38 AM
Re: What command to determine the current shell?
A user's default shell for login is defined in '/etc/passwd'.
For the c-shell, 'etc/csh.login' is sourced (read/executed) before '$HOME/.cshrc' and '$HOME/.login'.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-12-2003 11:39 AM
тАО02-12-2003 11:39 AM
Re: What command to determine the current shell?
# echo $SHELL will tell you the current shell.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-12-2003 11:39 AM
тАО02-12-2003 11:39 AM
Re: What command to determine the current shell?
Good luck,
Vince
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-12-2003 11:39 AM
тАО02-12-2003 11:39 AM
Re: What command to determine the current shell?
This will spanwned by your shell in /etc/passwd.
echo $SHELL
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-12-2003 11:40 AM
тАО02-12-2003 11:40 AM
Re: What command to determine the current shell?
I need to do something in a loop, so I run
% ksh
% echo $SHELL
/usr/bin/csh
Is there a way to do as the first question asks and get your current shell?
Regards,
Shannon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-12-2003 12:03 PM
тАО02-12-2003 12:03 PM
Re: What command to determine the current shell?
and look for ENV=
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-12-2003 12:03 PM
тАО02-12-2003 12:03 PM
Re: What command to determine the current shell?
and look for SHELL=
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-12-2003 12:10 PM
тАО02-12-2003 12:10 PM
Re: What command to determine the current shell?
I've blindly assumed for years that $SHELL contains your current shell. It seems that that is not the case - it's the shell that you're assigned from /etc/passwd by login.
Hmmmmm!
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-12-2003 12:10 PM
тАО02-12-2003 12:10 PM
Re: What command to determine the current shell?
or use a typo like lsls and it will come back saying
sh : lsls not found
/bin/ksh : lsls not found
Manoj Srivastava
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-12-2003 12:12 PM
тАО02-12-2003 12:12 PM
Re: What command to determine the current shell?
I for one have a tcsh for logon (as all state, the last field in the /etc/passwd file), but I've set my $SHELL environment to /usr/bin/sh for all the obvious reasons.
Fast way to check the last field of /etc/passwd
# grep "^`logname`:" /etc/passwd | sed 's/.*://'
do NOT rely on $LOGNAME, which is easy to overrule.
If you want to know for the /effective/ userid:
# perl -le'print+(getpwuid$>)[8]'
And, heh, that's even shorter than grep/sed, *and* more reliable. Now you've got easyEnjoy, have FUN! H.Merijnctionality *and* fun in one blow :)
and for the /real/ uid:
# perl -le'print+(getpwuid$<)[8]'
Enjoy, have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-12-2003 12:36 PM
тАО02-12-2003 12:36 PM
Re: What command to determine the current shell?
Further, there is no way that I know of to get your "current" shell, only the login shell.
One of them things I always wondered about.. figure it would be set somewhere, but.... maybe just me.
regards,
Shannon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-12-2003 12:59 PM
тАО02-12-2003 12:59 PM
Re: What command to determine the current shell?
currshell=`lsof -p $$ | awk '$4=="txt"{print $9}'`
This will give the path to the shell you are running (given by $$).
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-12-2003 01:10 PM
тАО02-12-2003 01:10 PM
Re: What command to determine the current shell?
echo $$ | tail -1 | awk '{print $NF}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-12-2003 01:10 PM
тАО02-12-2003 01:10 PM
Re: What command to determine the current shell?
Try this:
# ps |grep $$
10956 pts/0 0:00 csh
# ksh
# ps |grep $$
10963 pts/0 0:00 ksh
#
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-12-2003 02:34 PM
тАО02-12-2003 02:34 PM
Re: What command to determine the current shell?
Since ps -p $$ will only list the current process.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-13-2003 12:32 PM
тАО02-13-2003 12:32 PM
Re: What command to determine the current shell?
to the login shell), try "echo $0":
sh$ echo $0
sh
ksh$ echo $0
ksh
tcsh% echo $0
tcsh
csh% echo $0
No file for $0.
Unfortunately, csh seems to be the oddball.
Perhaps you could test $status after you
try the echo. If $status is 1, then you're
probably in csh. (I can't figure out how
to suppress the "No file for $0" message
or send it to /dev/null; chalk it up to csh's
weirdness.)
Just out of curiosity, why do you want to
determine the current shell? I can't think
of a good reason why one would do this.
Normally you're in the shell specified by
SHELL unless you started a new shell,
in which case you ought to know what
shell you're in, because you're the one
who changed it!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-13-2003 01:12 PM
тАО02-13-2003 01:12 PM
Re: What command to determine the current shell?
Unfortunatelly your solution won't work inside a running script.
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-13-2003 02:11 PM
тАО02-13-2003 02:11 PM
Re: What command to determine the current shell?
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-14-2003 06:44 PM
тАО02-14-2003 06:44 PM
Re: What command to determine the current shell?
the current shell interactively. In a
script, finding the current shell is
pointless, because the shell should
be set on the #! line. If it isn't set,
then exec() decides what to do
with your script. The man page
for exec() (HP-UX 10.20) says:
"If file does not have an executable
magic number (see magic(4)), it is
passed to the Bourne shell as a
shell script."
You can test this by saving these
lines to a file, then doing a "chmod
a+x" on the file. Then run the
script by typing its name.
echo `eval "if (1 == 1) then; echo 'this is a C-ish shell'; endif"`
echo `eval "[[ 1 = 1 ]] && echo 'this is a POSIX-ish shell'"`
echo `eval "[ 1 = 1 ] && echo 'this is a Bourne-ish shell'"`
If the script is running under csh or
tcsh, you'll see the first message,
followed by two errors.
If the script is running under ksh or
the POSIX sh, you'll see an error
followed by the second and third
messages.
If the script is running under the
Bourne sh, you'll see two errors,
followed by the third message.
The man page for exec() seems to be
out of date, because it evidently passes
the script to /usr/bin/sh, the POSIX shell.
But then again, this is all pretty pointless.