Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Possible Duplicate:
How to test what shell I am using in a terminal?

For example the following script



would issue:

share|improve this question

marked as duplicate by sr_, Stéphane Gimenez, Kevin, Gilles, Mat May 4 '12 at 10:23

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

yes, thank you for pointing me there –  Ingo May 3 '12 at 10:06
@jw013 more or less the same question but jippie's answer is better then the ones in the linked question :-) –  Matteo May 3 '12 at 18:52

2 Answers 2

ps h -p $$ -o args='' | cut -f1 -d' '
  • ps process list
  • h do not print column headers
  • -p <PID> list only process id PID
  • $$ replaced by the shell with current PID
  • -o args print the command line, no other information
  • cut cut the output into parts
  • -f1 print only the first field
  • -d' ' use a space as a field separator

    $ ./testje


share|improve this answer
On Mac OX X I get an additional line with the header ARGS. With -o args='' you can remove the header –  Matteo May 3 '12 at 18:50
Verified Matteo's comment on Linux (ubuntu 12.04) and works as designed. Updated my answer. –  jippie May 3 '12 at 18:55

If it's a local user, the 7th field of /etc/passwd is their shell. Are you looking for the currently preferred shell?

share|improve this answer
-1 The default login shell is not necessrily the one currently running. –  rahmu May 3 '12 at 12:05

Not the answer you're looking for? Browse other questions tagged or ask your own question.