This is a variable assignment. In this case a
is your variable and you are setting it to a null value; ''
will evaluate to nothing.
As ilkkachu points out:
Using a=''
is effectively no different than using a=""
or a=
As cas points out:
Setting the variable to a null value (or any initial/default value) also ensures you're not going to use whatever value it might have if it happens to be an environment variable (e.g. exported in the parent shell). This can be problem if, e.g., your script assumes that the variable is empty/undefined unless the script itself defines it, and takes different actions based on that.
script.sh
#!/bin/bash
if [[ $1 == null ]]; then
a=
elif [[ $1 == unset ]]; then
unset a
fi
echo "${a:-test}"
In action:
$ export a=value
$ ./script.sh null
test
$ ./script.sh unset
test
$ ./script.sh
value
$ echo $a
value
In many cases setting the variable to a null value is the same as unsetting the variable: unset a
However there are caveats
at least one