In the release for Bash-5.0 it is mentioned that they added
BASH_ARGV0: a new variable that expands to $0 and sets $0 on assignment.
What is the purpose of this? When is this an improvement over just using
The changelog says
- BASH_ARGV0: new dynamic variable, returns $0 on reference and sets $0 on assignment. From a suggestion from Rocky Bernstein <firstname.lastname@example.org> a few years ago
Rocky Bernstein is, among other things, the initial author of the BASH Debugger. When debugging, it can be useful to be able to set
$0 to different values; this led to this suggestion, ten years ago, of a
set0 built-in which would allow just that. I think
BASH_ARGV0 is the equivalent in the form of a special variable rather than a built-in.
$0 only allows you to read the value; before Bash 5, it could only be set when starting the shell.
BASH_ARGV0 allows you to write the value as well as read it.
0 isn’t a valid variable name for assignment purposes, and enabling
0=... would have been rather more complex.