Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a syntactical difference between single and double quoted empty strings?

Tags:

bash

According to the bash manual, there is no syntactical difference. The bash-parser on the other hand seems to have a different opinion on that when dealing with arithmetic expressions:

$ echo "$BASH_VERSION"
5.2.15(1)-release
$ echo $((""))
0
$ echo $((''))
bash: '': syntax error: operand expected (error token is "''")

Related:

  • Difference between single and double quotes in Bash
like image 831
kvantour Avatar asked Jan 24 '26 14:01

kvantour


1 Answers

There seems to be a subtle difference introduced in Bash 5.2. The manual states:

(( expression ))

The arithmetic expression is evaluated according to the rules described below (see Shell Arithmetic). The expression undergoes the same expansions as if it were within double quotes, but double quote characters in expression are not treated specially and are removed. If the value of the expression is non-zero, the return status is 0; otherwise the return status is 1.

Source: Bash Reference Manual: Section Conditional Constructs

This implies that (("")) is equivalent to (()) but (('')) is a syntactical error as single quotes are not removed from expression.

like image 196
kvantour Avatar answered Jan 27 '26 03:01

kvantour



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!