How to check which shell am I using?












274















I read that terminal is nothing but shell, and Unix provides different flavors of shells:




  • Bourne shell (sh)

  • C shell (csh)

  • TC shell (tcsh)

  • Korn shell (ksh)

  • Bourne Again shell (bash)


Questions:




  • When I open a terminal window, which shell is opened by default?

  • How do I check how many shells are installed?

  • How do I change the shell used from my account?










share|improve this question




















  • 4





    How to determine the current shell I'm working on? on stackoverflow.com

    – αғsнιη
    Feb 28 '15 at 4:16











  • @KasiyA This is also related to askubuntu.com/questions/87853/…

    – d a i s y
    Feb 1 '17 at 9:20
















274















I read that terminal is nothing but shell, and Unix provides different flavors of shells:




  • Bourne shell (sh)

  • C shell (csh)

  • TC shell (tcsh)

  • Korn shell (ksh)

  • Bourne Again shell (bash)


Questions:




  • When I open a terminal window, which shell is opened by default?

  • How do I check how many shells are installed?

  • How do I change the shell used from my account?










share|improve this question




















  • 4





    How to determine the current shell I'm working on? on stackoverflow.com

    – αғsнιη
    Feb 28 '15 at 4:16











  • @KasiyA This is also related to askubuntu.com/questions/87853/…

    – d a i s y
    Feb 1 '17 at 9:20














274












274








274


77






I read that terminal is nothing but shell, and Unix provides different flavors of shells:




  • Bourne shell (sh)

  • C shell (csh)

  • TC shell (tcsh)

  • Korn shell (ksh)

  • Bourne Again shell (bash)


Questions:




  • When I open a terminal window, which shell is opened by default?

  • How do I check how many shells are installed?

  • How do I change the shell used from my account?










share|improve this question
















I read that terminal is nothing but shell, and Unix provides different flavors of shells:




  • Bourne shell (sh)

  • C shell (csh)

  • TC shell (tcsh)

  • Korn shell (ksh)

  • Bourne Again shell (bash)


Questions:




  • When I open a terminal window, which shell is opened by default?

  • How do I check how many shells are installed?

  • How do I change the shell used from my account?







command-line






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 23 '17 at 21:47









David Foerster

28k1365111




28k1365111










asked Feb 28 '15 at 3:58









gouthamgoutham

1,508296




1,508296








  • 4





    How to determine the current shell I'm working on? on stackoverflow.com

    – αғsнιη
    Feb 28 '15 at 4:16











  • @KasiyA This is also related to askubuntu.com/questions/87853/…

    – d a i s y
    Feb 1 '17 at 9:20














  • 4





    How to determine the current shell I'm working on? on stackoverflow.com

    – αғsнιη
    Feb 28 '15 at 4:16











  • @KasiyA This is also related to askubuntu.com/questions/87853/…

    – d a i s y
    Feb 1 '17 at 9:20








4




4





How to determine the current shell I'm working on? on stackoverflow.com

– αғsнιη
Feb 28 '15 at 4:16





How to determine the current shell I'm working on? on stackoverflow.com

– αғsнιη
Feb 28 '15 at 4:16













@KasiyA This is also related to askubuntu.com/questions/87853/…

– d a i s y
Feb 1 '17 at 9:20





@KasiyA This is also related to askubuntu.com/questions/87853/…

– d a i s y
Feb 1 '17 at 9:20










6 Answers
6






active

oldest

votes


















341














You can type the following command in your terminal to see which shell you are using:



echo $0


The result will look something similar to the below if you are using the bash (Bourne Again Shell) terminal:



-bash





share|improve this answer





















  • 1





    is 0 an environment variable?

    – Mi_Onim
    Feb 22 '16 at 17:21






  • 31





    @Mi_Onim $0 is the name of the running process. If you use it inside of a shell then it will return the name of the shell. If you use it inside of a script, it will be the name of the script.

    – kingmilo
    Jun 26 '16 at 4:49






  • 1





    NOTE: this won't work for interactive csh. % echo $0 No file for $0. , but it does work for tcsh

    – Sergiy Kolodyazhnyy
    Sep 18 '16 at 12:43






  • 1





    Doesn't work if when one is symlink. Like bash as sh

    – Anwar
    Dec 6 '16 at 17:43






  • 8





    @Anwar makes a good point, after you get the shell name from echo $0, ls -l `which <name>` to see if it is symlinked to another shell binary.

    – JivanAmara
    Feb 10 '17 at 23:38





















93














To find the shell you have on the default environment you can check the value of the SHELL environment variable:



echo $SHELL


To find the current shell instance, look for the process (shell) having the PID of the current shell instance.



To find the PID of the current instance of shell:



echo "$$"


Now to find the process having the PID:



ps -p <PID>


Putting it together:



ps -p "$$"





share|improve this answer





















  • 16





    $SHELL is the default shell for the system (or user), which is usually (but not necessarily) the shell that is actually being used at any given moment.

    – kingmilo
    Feb 28 '15 at 4:13











  • @kingmilo: Right you are, answer modified.

    – heemayl
    Feb 28 '15 at 4:24











  • I found this pretty useful when switching to a user through 'su - <username>', e.g. for setting up postgres, jenkins, ...

    – bully
    Oct 7 '15 at 11:20











  • echo $SHELL gave me /bin/csh and ps -p $$ gave me 22673 pts/1 00:00:00 bash. Kingmilo explained (above) why they are not the same.

    – 18446744073709551615
    Oct 30 '17 at 10:32











  • @18446744073709551615 I have not said either that they are the same. Please read the answer carefully again; note the default and current wordings.

    – heemayl
    Oct 30 '17 at 13:34



















18














$SHELL gives you the default shell.
$0 gives you the current shell.



For example: I have bash as my default shell, which I use for my Terminal App. But for my iTerm2 app, I use the command as the window opens: /bin/ksh.



So my
$0 gives me /bin/ksh on iTerm2.
$SHELL gives me /bin/bash on iTerm2.
$0,$SHELL gives me /bin/bash on Terminal






share|improve this answer


























  • This is a nice disambiguation of the other top-voted answers. Thank you.

    – Michael Hoffmann
    Feb 14 '18 at 18:58



















7














To know which is the default shell for your user, you can run:



echo "$SHELL"


For example if you're using Bash you should get the following output:



/bin/bash


If you didn't change any configuration it should be Bash since Bash it's the default shell on Ubuntu.






share|improve this answer


























  • /bin/sh is the Shell Command Language and not the Bourne Shell, please edit your answer.

    – kingmilo
    Feb 28 '15 at 4:07











  • @kingmilo There's no /bin/sh reference in my answer

    – kos
    Feb 28 '15 at 4:12











  • @kol there was before edit. Please also note $SHELL is the default shell for the system (or user), which is usually (but not necessarily) the shell that is actually being used at any given moment.

    – kingmilo
    Feb 28 '15 at 4:14








  • 1





    @kingmilo Reading the answer again i think i understand what is your concern, probably i didn't express myself well. I clarified the meaning of "currently" in my answer

    – kos
    Feb 28 '15 at 4:49






  • 1





    @frederickjh fish is a bit of an odd one out here. The $$ variable is actually defined by POSIX and will work on the vast majority of shells. Fish has decided not to follow the standard here so I think it's fair to ignore it. I can confirm that $$ works as expected in sh, dash, bash, zsh, ksh, ash, tcsh and csh. In fact, off the top of my head I can't think of any other shell except fish where it doesn't work.

    – terdon
    Aug 18 '16 at 9:02



















6














The other answers tend to be using shell specific features, but we are trying to discover which shell we are using, so they assume the answer to the problem. For example none of the answers will work on fish.



sh -c 'ps -p $$ -o ppid=' | xargs ps -o cmd= -p


Instead use the $$ syntax in an invocation of sh, but then we are looking for the PPID not the PID. Use the PPID to find the cmd.



sh -c 'ps -p $$ -o ppid=' | xargs -i readlink -f /proc/{}/exe


Thanks for improvement @muru






share|improve this answer





















  • 2





    You ca use ppid=/cmd=to omit the headers (and so the tail -1s), and consider looking at /proc/.../exe to see what file is being run (since the cmd output can be manipulated by whatever ran the shell).

    – muru
    Apr 6 '18 at 4:07








  • 1





    Apparently this does not work in busybox, due to non posix compliance: ref: github.com/broadinstitute/cromwell/pull/…

    – Evan Benn
    Apr 30 '18 at 5:04



















4














The original post asked three questions. The answers given do cover the first question, "When I open a terminal window, which shell is opened by default?" They also answer a question which was NOT asked, namely "How can I find out which shell is currently running in the terminal?" However, as far as I can see nobody has answered either the second or third questions originally asked, namely "How do I check how many shells are installed?" and "How do I change the shell used from my account?"




  • To answer "How do I check how many shells are installed?" the following command will list all the available shells:


cat /etc/shells



For example, on a default installation of Ubuntu 18.10 this gives:



# /etc/shells: valid login shells



/bin/sh



/bin/dash



/bin/bash



/bin/rbash



However, by default sh is a symbolic link to dash, while rbash links to bash with the option -r ("restricted bash") so there are actually only two shells, not four as the above list suggests. The following command will show you whether any of the listed shells are in fact symbolic links, and if so where they link to:
ls -l /bin




  • Now for the question "How do I change the shell used from my account?" Assuming this means "How do I permanently change the default shell that a terminal will use", there is an answer at https://wiki.ubuntu.com/ChangingShells#Changing_your_login_shell_which_is_permanent






share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "89"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f590899%2fhow-to-check-which-shell-am-i-using%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    6 Answers
    6






    active

    oldest

    votes








    6 Answers
    6






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    341














    You can type the following command in your terminal to see which shell you are using:



    echo $0


    The result will look something similar to the below if you are using the bash (Bourne Again Shell) terminal:



    -bash





    share|improve this answer





















    • 1





      is 0 an environment variable?

      – Mi_Onim
      Feb 22 '16 at 17:21






    • 31





      @Mi_Onim $0 is the name of the running process. If you use it inside of a shell then it will return the name of the shell. If you use it inside of a script, it will be the name of the script.

      – kingmilo
      Jun 26 '16 at 4:49






    • 1





      NOTE: this won't work for interactive csh. % echo $0 No file for $0. , but it does work for tcsh

      – Sergiy Kolodyazhnyy
      Sep 18 '16 at 12:43






    • 1





      Doesn't work if when one is symlink. Like bash as sh

      – Anwar
      Dec 6 '16 at 17:43






    • 8





      @Anwar makes a good point, after you get the shell name from echo $0, ls -l `which <name>` to see if it is symlinked to another shell binary.

      – JivanAmara
      Feb 10 '17 at 23:38


















    341














    You can type the following command in your terminal to see which shell you are using:



    echo $0


    The result will look something similar to the below if you are using the bash (Bourne Again Shell) terminal:



    -bash





    share|improve this answer





















    • 1





      is 0 an environment variable?

      – Mi_Onim
      Feb 22 '16 at 17:21






    • 31





      @Mi_Onim $0 is the name of the running process. If you use it inside of a shell then it will return the name of the shell. If you use it inside of a script, it will be the name of the script.

      – kingmilo
      Jun 26 '16 at 4:49






    • 1





      NOTE: this won't work for interactive csh. % echo $0 No file for $0. , but it does work for tcsh

      – Sergiy Kolodyazhnyy
      Sep 18 '16 at 12:43






    • 1





      Doesn't work if when one is symlink. Like bash as sh

      – Anwar
      Dec 6 '16 at 17:43






    • 8





      @Anwar makes a good point, after you get the shell name from echo $0, ls -l `which <name>` to see if it is symlinked to another shell binary.

      – JivanAmara
      Feb 10 '17 at 23:38
















    341












    341








    341







    You can type the following command in your terminal to see which shell you are using:



    echo $0


    The result will look something similar to the below if you are using the bash (Bourne Again Shell) terminal:



    -bash





    share|improve this answer















    You can type the following command in your terminal to see which shell you are using:



    echo $0


    The result will look something similar to the below if you are using the bash (Bourne Again Shell) terminal:



    -bash






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jul 21 '16 at 2:58

























    answered Feb 28 '15 at 4:03









    kingmilokingmilo

    5,67111531




    5,67111531








    • 1





      is 0 an environment variable?

      – Mi_Onim
      Feb 22 '16 at 17:21






    • 31





      @Mi_Onim $0 is the name of the running process. If you use it inside of a shell then it will return the name of the shell. If you use it inside of a script, it will be the name of the script.

      – kingmilo
      Jun 26 '16 at 4:49






    • 1





      NOTE: this won't work for interactive csh. % echo $0 No file for $0. , but it does work for tcsh

      – Sergiy Kolodyazhnyy
      Sep 18 '16 at 12:43






    • 1





      Doesn't work if when one is symlink. Like bash as sh

      – Anwar
      Dec 6 '16 at 17:43






    • 8





      @Anwar makes a good point, after you get the shell name from echo $0, ls -l `which <name>` to see if it is symlinked to another shell binary.

      – JivanAmara
      Feb 10 '17 at 23:38
















    • 1





      is 0 an environment variable?

      – Mi_Onim
      Feb 22 '16 at 17:21






    • 31





      @Mi_Onim $0 is the name of the running process. If you use it inside of a shell then it will return the name of the shell. If you use it inside of a script, it will be the name of the script.

      – kingmilo
      Jun 26 '16 at 4:49






    • 1





      NOTE: this won't work for interactive csh. % echo $0 No file for $0. , but it does work for tcsh

      – Sergiy Kolodyazhnyy
      Sep 18 '16 at 12:43






    • 1





      Doesn't work if when one is symlink. Like bash as sh

      – Anwar
      Dec 6 '16 at 17:43






    • 8





      @Anwar makes a good point, after you get the shell name from echo $0, ls -l `which <name>` to see if it is symlinked to another shell binary.

      – JivanAmara
      Feb 10 '17 at 23:38










    1




    1





    is 0 an environment variable?

    – Mi_Onim
    Feb 22 '16 at 17:21





    is 0 an environment variable?

    – Mi_Onim
    Feb 22 '16 at 17:21




    31




    31





    @Mi_Onim $0 is the name of the running process. If you use it inside of a shell then it will return the name of the shell. If you use it inside of a script, it will be the name of the script.

    – kingmilo
    Jun 26 '16 at 4:49





    @Mi_Onim $0 is the name of the running process. If you use it inside of a shell then it will return the name of the shell. If you use it inside of a script, it will be the name of the script.

    – kingmilo
    Jun 26 '16 at 4:49




    1




    1





    NOTE: this won't work for interactive csh. % echo $0 No file for $0. , but it does work for tcsh

    – Sergiy Kolodyazhnyy
    Sep 18 '16 at 12:43





    NOTE: this won't work for interactive csh. % echo $0 No file for $0. , but it does work for tcsh

    – Sergiy Kolodyazhnyy
    Sep 18 '16 at 12:43




    1




    1





    Doesn't work if when one is symlink. Like bash as sh

    – Anwar
    Dec 6 '16 at 17:43





    Doesn't work if when one is symlink. Like bash as sh

    – Anwar
    Dec 6 '16 at 17:43




    8




    8





    @Anwar makes a good point, after you get the shell name from echo $0, ls -l `which <name>` to see if it is symlinked to another shell binary.

    – JivanAmara
    Feb 10 '17 at 23:38







    @Anwar makes a good point, after you get the shell name from echo $0, ls -l `which <name>` to see if it is symlinked to another shell binary.

    – JivanAmara
    Feb 10 '17 at 23:38















    93














    To find the shell you have on the default environment you can check the value of the SHELL environment variable:



    echo $SHELL


    To find the current shell instance, look for the process (shell) having the PID of the current shell instance.



    To find the PID of the current instance of shell:



    echo "$$"


    Now to find the process having the PID:



    ps -p <PID>


    Putting it together:



    ps -p "$$"





    share|improve this answer





















    • 16





      $SHELL is the default shell for the system (or user), which is usually (but not necessarily) the shell that is actually being used at any given moment.

      – kingmilo
      Feb 28 '15 at 4:13











    • @kingmilo: Right you are, answer modified.

      – heemayl
      Feb 28 '15 at 4:24











    • I found this pretty useful when switching to a user through 'su - <username>', e.g. for setting up postgres, jenkins, ...

      – bully
      Oct 7 '15 at 11:20











    • echo $SHELL gave me /bin/csh and ps -p $$ gave me 22673 pts/1 00:00:00 bash. Kingmilo explained (above) why they are not the same.

      – 18446744073709551615
      Oct 30 '17 at 10:32











    • @18446744073709551615 I have not said either that they are the same. Please read the answer carefully again; note the default and current wordings.

      – heemayl
      Oct 30 '17 at 13:34
















    93














    To find the shell you have on the default environment you can check the value of the SHELL environment variable:



    echo $SHELL


    To find the current shell instance, look for the process (shell) having the PID of the current shell instance.



    To find the PID of the current instance of shell:



    echo "$$"


    Now to find the process having the PID:



    ps -p <PID>


    Putting it together:



    ps -p "$$"





    share|improve this answer





















    • 16





      $SHELL is the default shell for the system (or user), which is usually (but not necessarily) the shell that is actually being used at any given moment.

      – kingmilo
      Feb 28 '15 at 4:13











    • @kingmilo: Right you are, answer modified.

      – heemayl
      Feb 28 '15 at 4:24











    • I found this pretty useful when switching to a user through 'su - <username>', e.g. for setting up postgres, jenkins, ...

      – bully
      Oct 7 '15 at 11:20











    • echo $SHELL gave me /bin/csh and ps -p $$ gave me 22673 pts/1 00:00:00 bash. Kingmilo explained (above) why they are not the same.

      – 18446744073709551615
      Oct 30 '17 at 10:32











    • @18446744073709551615 I have not said either that they are the same. Please read the answer carefully again; note the default and current wordings.

      – heemayl
      Oct 30 '17 at 13:34














    93












    93








    93







    To find the shell you have on the default environment you can check the value of the SHELL environment variable:



    echo $SHELL


    To find the current shell instance, look for the process (shell) having the PID of the current shell instance.



    To find the PID of the current instance of shell:



    echo "$$"


    Now to find the process having the PID:



    ps -p <PID>


    Putting it together:



    ps -p "$$"





    share|improve this answer















    To find the shell you have on the default environment you can check the value of the SHELL environment variable:



    echo $SHELL


    To find the current shell instance, look for the process (shell) having the PID of the current shell instance.



    To find the PID of the current instance of shell:



    echo "$$"


    Now to find the process having the PID:



    ps -p <PID>


    Putting it together:



    ps -p "$$"






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Feb 28 '15 at 4:23

























    answered Feb 28 '15 at 4:06









    heemaylheemayl

    66.4k8139212




    66.4k8139212








    • 16





      $SHELL is the default shell for the system (or user), which is usually (but not necessarily) the shell that is actually being used at any given moment.

      – kingmilo
      Feb 28 '15 at 4:13











    • @kingmilo: Right you are, answer modified.

      – heemayl
      Feb 28 '15 at 4:24











    • I found this pretty useful when switching to a user through 'su - <username>', e.g. for setting up postgres, jenkins, ...

      – bully
      Oct 7 '15 at 11:20











    • echo $SHELL gave me /bin/csh and ps -p $$ gave me 22673 pts/1 00:00:00 bash. Kingmilo explained (above) why they are not the same.

      – 18446744073709551615
      Oct 30 '17 at 10:32











    • @18446744073709551615 I have not said either that they are the same. Please read the answer carefully again; note the default and current wordings.

      – heemayl
      Oct 30 '17 at 13:34














    • 16





      $SHELL is the default shell for the system (or user), which is usually (but not necessarily) the shell that is actually being used at any given moment.

      – kingmilo
      Feb 28 '15 at 4:13











    • @kingmilo: Right you are, answer modified.

      – heemayl
      Feb 28 '15 at 4:24











    • I found this pretty useful when switching to a user through 'su - <username>', e.g. for setting up postgres, jenkins, ...

      – bully
      Oct 7 '15 at 11:20











    • echo $SHELL gave me /bin/csh and ps -p $$ gave me 22673 pts/1 00:00:00 bash. Kingmilo explained (above) why they are not the same.

      – 18446744073709551615
      Oct 30 '17 at 10:32











    • @18446744073709551615 I have not said either that they are the same. Please read the answer carefully again; note the default and current wordings.

      – heemayl
      Oct 30 '17 at 13:34








    16




    16





    $SHELL is the default shell for the system (or user), which is usually (but not necessarily) the shell that is actually being used at any given moment.

    – kingmilo
    Feb 28 '15 at 4:13





    $SHELL is the default shell for the system (or user), which is usually (but not necessarily) the shell that is actually being used at any given moment.

    – kingmilo
    Feb 28 '15 at 4:13













    @kingmilo: Right you are, answer modified.

    – heemayl
    Feb 28 '15 at 4:24





    @kingmilo: Right you are, answer modified.

    – heemayl
    Feb 28 '15 at 4:24













    I found this pretty useful when switching to a user through 'su - <username>', e.g. for setting up postgres, jenkins, ...

    – bully
    Oct 7 '15 at 11:20





    I found this pretty useful when switching to a user through 'su - <username>', e.g. for setting up postgres, jenkins, ...

    – bully
    Oct 7 '15 at 11:20













    echo $SHELL gave me /bin/csh and ps -p $$ gave me 22673 pts/1 00:00:00 bash. Kingmilo explained (above) why they are not the same.

    – 18446744073709551615
    Oct 30 '17 at 10:32





    echo $SHELL gave me /bin/csh and ps -p $$ gave me 22673 pts/1 00:00:00 bash. Kingmilo explained (above) why they are not the same.

    – 18446744073709551615
    Oct 30 '17 at 10:32













    @18446744073709551615 I have not said either that they are the same. Please read the answer carefully again; note the default and current wordings.

    – heemayl
    Oct 30 '17 at 13:34





    @18446744073709551615 I have not said either that they are the same. Please read the answer carefully again; note the default and current wordings.

    – heemayl
    Oct 30 '17 at 13:34











    18














    $SHELL gives you the default shell.
    $0 gives you the current shell.



    For example: I have bash as my default shell, which I use for my Terminal App. But for my iTerm2 app, I use the command as the window opens: /bin/ksh.



    So my
    $0 gives me /bin/ksh on iTerm2.
    $SHELL gives me /bin/bash on iTerm2.
    $0,$SHELL gives me /bin/bash on Terminal






    share|improve this answer


























    • This is a nice disambiguation of the other top-voted answers. Thank you.

      – Michael Hoffmann
      Feb 14 '18 at 18:58
















    18














    $SHELL gives you the default shell.
    $0 gives you the current shell.



    For example: I have bash as my default shell, which I use for my Terminal App. But for my iTerm2 app, I use the command as the window opens: /bin/ksh.



    So my
    $0 gives me /bin/ksh on iTerm2.
    $SHELL gives me /bin/bash on iTerm2.
    $0,$SHELL gives me /bin/bash on Terminal






    share|improve this answer


























    • This is a nice disambiguation of the other top-voted answers. Thank you.

      – Michael Hoffmann
      Feb 14 '18 at 18:58














    18












    18








    18







    $SHELL gives you the default shell.
    $0 gives you the current shell.



    For example: I have bash as my default shell, which I use for my Terminal App. But for my iTerm2 app, I use the command as the window opens: /bin/ksh.



    So my
    $0 gives me /bin/ksh on iTerm2.
    $SHELL gives me /bin/bash on iTerm2.
    $0,$SHELL gives me /bin/bash on Terminal






    share|improve this answer















    $SHELL gives you the default shell.
    $0 gives you the current shell.



    For example: I have bash as my default shell, which I use for my Terminal App. But for my iTerm2 app, I use the command as the window opens: /bin/ksh.



    So my
    $0 gives me /bin/ksh on iTerm2.
    $SHELL gives me /bin/bash on iTerm2.
    $0,$SHELL gives me /bin/bash on Terminal







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 18 '16 at 13:15









    muru

    1




    1










    answered Nov 18 '16 at 11:45









    nakulchawla09nakulchawla09

    28828




    28828













    • This is a nice disambiguation of the other top-voted answers. Thank you.

      – Michael Hoffmann
      Feb 14 '18 at 18:58



















    • This is a nice disambiguation of the other top-voted answers. Thank you.

      – Michael Hoffmann
      Feb 14 '18 at 18:58

















    This is a nice disambiguation of the other top-voted answers. Thank you.

    – Michael Hoffmann
    Feb 14 '18 at 18:58





    This is a nice disambiguation of the other top-voted answers. Thank you.

    – Michael Hoffmann
    Feb 14 '18 at 18:58











    7














    To know which is the default shell for your user, you can run:



    echo "$SHELL"


    For example if you're using Bash you should get the following output:



    /bin/bash


    If you didn't change any configuration it should be Bash since Bash it's the default shell on Ubuntu.






    share|improve this answer


























    • /bin/sh is the Shell Command Language and not the Bourne Shell, please edit your answer.

      – kingmilo
      Feb 28 '15 at 4:07











    • @kingmilo There's no /bin/sh reference in my answer

      – kos
      Feb 28 '15 at 4:12











    • @kol there was before edit. Please also note $SHELL is the default shell for the system (or user), which is usually (but not necessarily) the shell that is actually being used at any given moment.

      – kingmilo
      Feb 28 '15 at 4:14








    • 1





      @kingmilo Reading the answer again i think i understand what is your concern, probably i didn't express myself well. I clarified the meaning of "currently" in my answer

      – kos
      Feb 28 '15 at 4:49






    • 1





      @frederickjh fish is a bit of an odd one out here. The $$ variable is actually defined by POSIX and will work on the vast majority of shells. Fish has decided not to follow the standard here so I think it's fair to ignore it. I can confirm that $$ works as expected in sh, dash, bash, zsh, ksh, ash, tcsh and csh. In fact, off the top of my head I can't think of any other shell except fish where it doesn't work.

      – terdon
      Aug 18 '16 at 9:02
















    7














    To know which is the default shell for your user, you can run:



    echo "$SHELL"


    For example if you're using Bash you should get the following output:



    /bin/bash


    If you didn't change any configuration it should be Bash since Bash it's the default shell on Ubuntu.






    share|improve this answer


























    • /bin/sh is the Shell Command Language and not the Bourne Shell, please edit your answer.

      – kingmilo
      Feb 28 '15 at 4:07











    • @kingmilo There's no /bin/sh reference in my answer

      – kos
      Feb 28 '15 at 4:12











    • @kol there was before edit. Please also note $SHELL is the default shell for the system (or user), which is usually (but not necessarily) the shell that is actually being used at any given moment.

      – kingmilo
      Feb 28 '15 at 4:14








    • 1





      @kingmilo Reading the answer again i think i understand what is your concern, probably i didn't express myself well. I clarified the meaning of "currently" in my answer

      – kos
      Feb 28 '15 at 4:49






    • 1





      @frederickjh fish is a bit of an odd one out here. The $$ variable is actually defined by POSIX and will work on the vast majority of shells. Fish has decided not to follow the standard here so I think it's fair to ignore it. I can confirm that $$ works as expected in sh, dash, bash, zsh, ksh, ash, tcsh and csh. In fact, off the top of my head I can't think of any other shell except fish where it doesn't work.

      – terdon
      Aug 18 '16 at 9:02














    7












    7








    7







    To know which is the default shell for your user, you can run:



    echo "$SHELL"


    For example if you're using Bash you should get the following output:



    /bin/bash


    If you didn't change any configuration it should be Bash since Bash it's the default shell on Ubuntu.






    share|improve this answer















    To know which is the default shell for your user, you can run:



    echo "$SHELL"


    For example if you're using Bash you should get the following output:



    /bin/bash


    If you didn't change any configuration it should be Bash since Bash it's the default shell on Ubuntu.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Apr 17 '16 at 19:12

























    answered Feb 28 '15 at 4:02









    koskos

    25.5k870121




    25.5k870121













    • /bin/sh is the Shell Command Language and not the Bourne Shell, please edit your answer.

      – kingmilo
      Feb 28 '15 at 4:07











    • @kingmilo There's no /bin/sh reference in my answer

      – kos
      Feb 28 '15 at 4:12











    • @kol there was before edit. Please also note $SHELL is the default shell for the system (or user), which is usually (but not necessarily) the shell that is actually being used at any given moment.

      – kingmilo
      Feb 28 '15 at 4:14








    • 1





      @kingmilo Reading the answer again i think i understand what is your concern, probably i didn't express myself well. I clarified the meaning of "currently" in my answer

      – kos
      Feb 28 '15 at 4:49






    • 1





      @frederickjh fish is a bit of an odd one out here. The $$ variable is actually defined by POSIX and will work on the vast majority of shells. Fish has decided not to follow the standard here so I think it's fair to ignore it. I can confirm that $$ works as expected in sh, dash, bash, zsh, ksh, ash, tcsh and csh. In fact, off the top of my head I can't think of any other shell except fish where it doesn't work.

      – terdon
      Aug 18 '16 at 9:02



















    • /bin/sh is the Shell Command Language and not the Bourne Shell, please edit your answer.

      – kingmilo
      Feb 28 '15 at 4:07











    • @kingmilo There's no /bin/sh reference in my answer

      – kos
      Feb 28 '15 at 4:12











    • @kol there was before edit. Please also note $SHELL is the default shell for the system (or user), which is usually (but not necessarily) the shell that is actually being used at any given moment.

      – kingmilo
      Feb 28 '15 at 4:14








    • 1





      @kingmilo Reading the answer again i think i understand what is your concern, probably i didn't express myself well. I clarified the meaning of "currently" in my answer

      – kos
      Feb 28 '15 at 4:49






    • 1





      @frederickjh fish is a bit of an odd one out here. The $$ variable is actually defined by POSIX and will work on the vast majority of shells. Fish has decided not to follow the standard here so I think it's fair to ignore it. I can confirm that $$ works as expected in sh, dash, bash, zsh, ksh, ash, tcsh and csh. In fact, off the top of my head I can't think of any other shell except fish where it doesn't work.

      – terdon
      Aug 18 '16 at 9:02

















    /bin/sh is the Shell Command Language and not the Bourne Shell, please edit your answer.

    – kingmilo
    Feb 28 '15 at 4:07





    /bin/sh is the Shell Command Language and not the Bourne Shell, please edit your answer.

    – kingmilo
    Feb 28 '15 at 4:07













    @kingmilo There's no /bin/sh reference in my answer

    – kos
    Feb 28 '15 at 4:12





    @kingmilo There's no /bin/sh reference in my answer

    – kos
    Feb 28 '15 at 4:12













    @kol there was before edit. Please also note $SHELL is the default shell for the system (or user), which is usually (but not necessarily) the shell that is actually being used at any given moment.

    – kingmilo
    Feb 28 '15 at 4:14







    @kol there was before edit. Please also note $SHELL is the default shell for the system (or user), which is usually (but not necessarily) the shell that is actually being used at any given moment.

    – kingmilo
    Feb 28 '15 at 4:14






    1




    1





    @kingmilo Reading the answer again i think i understand what is your concern, probably i didn't express myself well. I clarified the meaning of "currently" in my answer

    – kos
    Feb 28 '15 at 4:49





    @kingmilo Reading the answer again i think i understand what is your concern, probably i didn't express myself well. I clarified the meaning of "currently" in my answer

    – kos
    Feb 28 '15 at 4:49




    1




    1





    @frederickjh fish is a bit of an odd one out here. The $$ variable is actually defined by POSIX and will work on the vast majority of shells. Fish has decided not to follow the standard here so I think it's fair to ignore it. I can confirm that $$ works as expected in sh, dash, bash, zsh, ksh, ash, tcsh and csh. In fact, off the top of my head I can't think of any other shell except fish where it doesn't work.

    – terdon
    Aug 18 '16 at 9:02





    @frederickjh fish is a bit of an odd one out here. The $$ variable is actually defined by POSIX and will work on the vast majority of shells. Fish has decided not to follow the standard here so I think it's fair to ignore it. I can confirm that $$ works as expected in sh, dash, bash, zsh, ksh, ash, tcsh and csh. In fact, off the top of my head I can't think of any other shell except fish where it doesn't work.

    – terdon
    Aug 18 '16 at 9:02











    6














    The other answers tend to be using shell specific features, but we are trying to discover which shell we are using, so they assume the answer to the problem. For example none of the answers will work on fish.



    sh -c 'ps -p $$ -o ppid=' | xargs ps -o cmd= -p


    Instead use the $$ syntax in an invocation of sh, but then we are looking for the PPID not the PID. Use the PPID to find the cmd.



    sh -c 'ps -p $$ -o ppid=' | xargs -i readlink -f /proc/{}/exe


    Thanks for improvement @muru






    share|improve this answer





















    • 2





      You ca use ppid=/cmd=to omit the headers (and so the tail -1s), and consider looking at /proc/.../exe to see what file is being run (since the cmd output can be manipulated by whatever ran the shell).

      – muru
      Apr 6 '18 at 4:07








    • 1





      Apparently this does not work in busybox, due to non posix compliance: ref: github.com/broadinstitute/cromwell/pull/…

      – Evan Benn
      Apr 30 '18 at 5:04
















    6














    The other answers tend to be using shell specific features, but we are trying to discover which shell we are using, so they assume the answer to the problem. For example none of the answers will work on fish.



    sh -c 'ps -p $$ -o ppid=' | xargs ps -o cmd= -p


    Instead use the $$ syntax in an invocation of sh, but then we are looking for the PPID not the PID. Use the PPID to find the cmd.



    sh -c 'ps -p $$ -o ppid=' | xargs -i readlink -f /proc/{}/exe


    Thanks for improvement @muru






    share|improve this answer





















    • 2





      You ca use ppid=/cmd=to omit the headers (and so the tail -1s), and consider looking at /proc/.../exe to see what file is being run (since the cmd output can be manipulated by whatever ran the shell).

      – muru
      Apr 6 '18 at 4:07








    • 1





      Apparently this does not work in busybox, due to non posix compliance: ref: github.com/broadinstitute/cromwell/pull/…

      – Evan Benn
      Apr 30 '18 at 5:04














    6












    6








    6







    The other answers tend to be using shell specific features, but we are trying to discover which shell we are using, so they assume the answer to the problem. For example none of the answers will work on fish.



    sh -c 'ps -p $$ -o ppid=' | xargs ps -o cmd= -p


    Instead use the $$ syntax in an invocation of sh, but then we are looking for the PPID not the PID. Use the PPID to find the cmd.



    sh -c 'ps -p $$ -o ppid=' | xargs -i readlink -f /proc/{}/exe


    Thanks for improvement @muru






    share|improve this answer















    The other answers tend to be using shell specific features, but we are trying to discover which shell we are using, so they assume the answer to the problem. For example none of the answers will work on fish.



    sh -c 'ps -p $$ -o ppid=' | xargs ps -o cmd= -p


    Instead use the $$ syntax in an invocation of sh, but then we are looking for the PPID not the PID. Use the PPID to find the cmd.



    sh -c 'ps -p $$ -o ppid=' | xargs -i readlink -f /proc/{}/exe


    Thanks for improvement @muru







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Apr 10 '18 at 4:19

























    answered Apr 6 '18 at 4:00









    Evan BennEvan Benn

    16113




    16113








    • 2





      You ca use ppid=/cmd=to omit the headers (and so the tail -1s), and consider looking at /proc/.../exe to see what file is being run (since the cmd output can be manipulated by whatever ran the shell).

      – muru
      Apr 6 '18 at 4:07








    • 1





      Apparently this does not work in busybox, due to non posix compliance: ref: github.com/broadinstitute/cromwell/pull/…

      – Evan Benn
      Apr 30 '18 at 5:04














    • 2





      You ca use ppid=/cmd=to omit the headers (and so the tail -1s), and consider looking at /proc/.../exe to see what file is being run (since the cmd output can be manipulated by whatever ran the shell).

      – muru
      Apr 6 '18 at 4:07








    • 1





      Apparently this does not work in busybox, due to non posix compliance: ref: github.com/broadinstitute/cromwell/pull/…

      – Evan Benn
      Apr 30 '18 at 5:04








    2




    2





    You ca use ppid=/cmd=to omit the headers (and so the tail -1s), and consider looking at /proc/.../exe to see what file is being run (since the cmd output can be manipulated by whatever ran the shell).

    – muru
    Apr 6 '18 at 4:07







    You ca use ppid=/cmd=to omit the headers (and so the tail -1s), and consider looking at /proc/.../exe to see what file is being run (since the cmd output can be manipulated by whatever ran the shell).

    – muru
    Apr 6 '18 at 4:07






    1




    1





    Apparently this does not work in busybox, due to non posix compliance: ref: github.com/broadinstitute/cromwell/pull/…

    – Evan Benn
    Apr 30 '18 at 5:04





    Apparently this does not work in busybox, due to non posix compliance: ref: github.com/broadinstitute/cromwell/pull/…

    – Evan Benn
    Apr 30 '18 at 5:04











    4














    The original post asked three questions. The answers given do cover the first question, "When I open a terminal window, which shell is opened by default?" They also answer a question which was NOT asked, namely "How can I find out which shell is currently running in the terminal?" However, as far as I can see nobody has answered either the second or third questions originally asked, namely "How do I check how many shells are installed?" and "How do I change the shell used from my account?"




    • To answer "How do I check how many shells are installed?" the following command will list all the available shells:


    cat /etc/shells



    For example, on a default installation of Ubuntu 18.10 this gives:



    # /etc/shells: valid login shells



    /bin/sh



    /bin/dash



    /bin/bash



    /bin/rbash



    However, by default sh is a symbolic link to dash, while rbash links to bash with the option -r ("restricted bash") so there are actually only two shells, not four as the above list suggests. The following command will show you whether any of the listed shells are in fact symbolic links, and if so where they link to:
    ls -l /bin




    • Now for the question "How do I change the shell used from my account?" Assuming this means "How do I permanently change the default shell that a terminal will use", there is an answer at https://wiki.ubuntu.com/ChangingShells#Changing_your_login_shell_which_is_permanent






    share|improve this answer




























      4














      The original post asked three questions. The answers given do cover the first question, "When I open a terminal window, which shell is opened by default?" They also answer a question which was NOT asked, namely "How can I find out which shell is currently running in the terminal?" However, as far as I can see nobody has answered either the second or third questions originally asked, namely "How do I check how many shells are installed?" and "How do I change the shell used from my account?"




      • To answer "How do I check how many shells are installed?" the following command will list all the available shells:


      cat /etc/shells



      For example, on a default installation of Ubuntu 18.10 this gives:



      # /etc/shells: valid login shells



      /bin/sh



      /bin/dash



      /bin/bash



      /bin/rbash



      However, by default sh is a symbolic link to dash, while rbash links to bash with the option -r ("restricted bash") so there are actually only two shells, not four as the above list suggests. The following command will show you whether any of the listed shells are in fact symbolic links, and if so where they link to:
      ls -l /bin




      • Now for the question "How do I change the shell used from my account?" Assuming this means "How do I permanently change the default shell that a terminal will use", there is an answer at https://wiki.ubuntu.com/ChangingShells#Changing_your_login_shell_which_is_permanent






      share|improve this answer


























        4












        4








        4







        The original post asked three questions. The answers given do cover the first question, "When I open a terminal window, which shell is opened by default?" They also answer a question which was NOT asked, namely "How can I find out which shell is currently running in the terminal?" However, as far as I can see nobody has answered either the second or third questions originally asked, namely "How do I check how many shells are installed?" and "How do I change the shell used from my account?"




        • To answer "How do I check how many shells are installed?" the following command will list all the available shells:


        cat /etc/shells



        For example, on a default installation of Ubuntu 18.10 this gives:



        # /etc/shells: valid login shells



        /bin/sh



        /bin/dash



        /bin/bash



        /bin/rbash



        However, by default sh is a symbolic link to dash, while rbash links to bash with the option -r ("restricted bash") so there are actually only two shells, not four as the above list suggests. The following command will show you whether any of the listed shells are in fact symbolic links, and if so where they link to:
        ls -l /bin




        • Now for the question "How do I change the shell used from my account?" Assuming this means "How do I permanently change the default shell that a terminal will use", there is an answer at https://wiki.ubuntu.com/ChangingShells#Changing_your_login_shell_which_is_permanent






        share|improve this answer













        The original post asked three questions. The answers given do cover the first question, "When I open a terminal window, which shell is opened by default?" They also answer a question which was NOT asked, namely "How can I find out which shell is currently running in the terminal?" However, as far as I can see nobody has answered either the second or third questions originally asked, namely "How do I check how many shells are installed?" and "How do I change the shell used from my account?"




        • To answer "How do I check how many shells are installed?" the following command will list all the available shells:


        cat /etc/shells



        For example, on a default installation of Ubuntu 18.10 this gives:



        # /etc/shells: valid login shells



        /bin/sh



        /bin/dash



        /bin/bash



        /bin/rbash



        However, by default sh is a symbolic link to dash, while rbash links to bash with the option -r ("restricted bash") so there are actually only two shells, not four as the above list suggests. The following command will show you whether any of the listed shells are in fact symbolic links, and if so where they link to:
        ls -l /bin




        • Now for the question "How do I change the shell used from my account?" Assuming this means "How do I permanently change the default shell that a terminal will use", there is an answer at https://wiki.ubuntu.com/ChangingShells#Changing_your_login_shell_which_is_permanent







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 7 '18 at 11:54









        Michael DMichael D

        585




        585






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Ask Ubuntu!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f590899%2fhow-to-check-which-shell-am-i-using%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How did Captain America manage to do this?

            迪纳利

            南乌拉尔铁路局