What Does $0 Do in Linux?

What Does $0 Do in Linux?
Contents

$0 Expands to the name of the shell or shell script. This is set at shell initialization. If Bash is invoked with a file of commands (see Section 3.8 [Shell Scripts], page 39), $0 is set to the name of that file.

What does echo $0 Do?

As explained in this comment on that answer you link to, echo $0 simply shows you the name of the currently running process: $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.

What is the meaning of the $0 variable in awk?

$0 signifies the entire record. In addition, a variable named NF is set containing the number of fields detected in the record. Pattern/action pairs are tests and corresponding actions to be performed on each record. … For example, $0 represents the value of the entire record the AWK program read on standard input.

Sarah Jenkins
Author

Sarah Jenkins

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.