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

I want to detect which interpreter a shell script is using. For example the following script:



Should reveal the interpreter:


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.

  • @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
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


  • 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
  • 1
    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?

  • 2
    -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.