Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between error= and error=''

Tags:

bash

In Bash is there a difference between these two variable definitions?

error=
error=''

Testing them on emptiness / being unset seems to suggest that they are equal but I still I would like to be sure.

like image 817
helpermethod Avatar asked Feb 08 '23 22:02

helpermethod


1 Answers

Short answer: No, there are no differences at all. The quotes are stripped during parsing.


From the Variable Assignment section of the POSIX reference:

In the shell command language, a word consisting of the following parts:

varname=value

and a few lines below you'll see:

If value is not specified, the variable shall be given a null value.

To check this (in Bash):

$ variable1=
$ variable2=''
$ declare -p variable{1,2}
declare -- variable1=""
declare -- variable2=""

they do look identical!

like image 122
gniourf_gniourf Avatar answered Feb 19 '23 17:02

gniourf_gniourf