What is the Difference Between 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!

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!