What is the Difference Between $SHELL and $0 Environment Variables?


Both $SHELL and $0 are environment variables that provide information related to the shell in Unix or Unix-like operating systems, but they differ in the following ways.

$SHELL

  • This environment variable stores the path to the default shell for the logged-in user.
  • Example:
    $ echo $SHELL
    /bin/bash
    
    $ sh
    sh-3.2 $ echo $SHELL
    /bin/bash

    In the above example, irrespective of the shell that you are currently using, $SHELL will give you the default shell path set for the active user.

$0

  • This environment variable provides the name of the current shell when used on any interactive shell prompt. Note that if used within a script, it will give you the name of the script being executed.
  • Example:
    $ echo $0
    bash
    
    $ zsh
    % echo $0
    zsh

    In the above example, you get the name of the current shell when $0 is echoed.

$SHELL vs $0 Example

This is not an AI-generated article but is demonstrated by a human.

Please support independent contributors like Code2care by donating a coffee.

Buy me a coffee!

Buy Code2care a Coffee!

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap