Skip to content
The Bash Insectarium

/static/insetario/en/inseto/zero/

Menu

BSH-023 · Ghost variables

$0

The name the script was called by — itself, on the label.

Inside a script, $0 is the path used to invoke it — raw material for usage messages: usage: $0 file…. In an interactive shell, it is the shell's own name.

It stays out of the positional dance: shift moves $1, $2 and onward, but $0 does not budge.

$ cat identifica.sh
#!/bin/bash
echo "eu sou $0"
$ ./identifica.sh
eu sou ./identifica.sh
The script says its own name.