What Is the Meaning of "$0" in Shell?

Generally speaking, $0 is a special parameter available in POSIX compliant shells which refers to the name of the currently running process. This means that when it is used inside a shell it will return the name of the shell, and when it is used inside a script, it will return the name of the script, etc. Therefore, if you echo it in terminal, you will see the name of the shell being output:

echo $0 # output: -zsh

Please note that the dash in front of the shell name has a special meaning. You might see it in the shell name output, depending on the way your shell was invoked.


This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.