Skip to main content
added 155 characters in body
Source Link
MC68020
  • 8.2k
  • 3
  • 19
  • 49

The $ sign introduces parameter expansion, command substitution, or arithmetic expansion

In your second case ($var unquoted) since $var is empty, it will expand to nothing. Just as if you had not specified any operand to the test.

In your first case, ($var double quoted) $var will still expand to nothing but within the double quotes, this incidentally providing the empty string "" as operand to the test.


Update following additional question from OP in commentsadditional question from OP in comments :

why doesn't -n with no operand lead to, for example, "error: -n requires an operand"?

To which I had initially answered that, according to the manual, test

Exits with a status of 0 (true) or 1 (false)

With false including the case where "an invalid argument is given".

Some comment from illkachu provides a deeper insight :

A few test implementations (including Bash's) actually do return a distinct falsy status for an error, i.e. 0 for true, 1 for false and 2 for error

However :

It's just that both 1 and 2 are falsy as far as shell conditionals are concerned

The $ sign introduces parameter expansion, command substitution, or arithmetic expansion

In your second case ($var unquoted) since $var is empty, it will expand to nothing. Just as if you had not specified any operand to the test.

In your first case, ($var double quoted) $var will still expand to nothing but within the double quotes, this incidentally providing the empty string "" as operand to the test.


Update following additional question from OP in comments :

why doesn't -n with no operand lead to, for example, "error: -n requires an operand"?

To which I had initially answered that, according to the manual, test

Exits with a status of 0 (true) or 1 (false)

With false including the case where "an invalid argument is given".

Some comment from illkachu provides a deeper insight :

A few test implementations (including Bash's) actually do return a distinct falsy status for an error, i.e. 0 for true, 1 for false and 2 for error

However :

It's just that both 1 and 2 are falsy as far as shell conditionals are concerned

The $ sign introduces parameter expansion, command substitution, or arithmetic expansion

In your second case ($var unquoted) since $var is empty, it will expand to nothing. Just as if you had not specified any operand to the test.

In your first case, ($var double quoted) $var will still expand to nothing but within the double quotes, this incidentally providing the empty string "" as operand to the test.


Update following additional question from OP in comments :

why doesn't -n with no operand lead to, for example, "error: -n requires an operand"?

To which I had initially answered that, according to the manual, test

Exits with a status of 0 (true) or 1 (false)

With false including the case where "an invalid argument is given".

Some comment from illkachu provides a deeper insight :

A few test implementations (including Bash's) actually do return a distinct falsy status for an error, i.e. 0 for true, 1 for false and 2 for error

However :

It's just that both 1 and 2 are falsy as far as shell conditionals are concerned

added 921 characters in body
Source Link
MC68020
  • 8.2k
  • 3
  • 19
  • 49

The $ sign introduces parameter expansion, command substitution, or arithmetic expansion

In your second case ($var unquoted) since $var is empty, it will expand to nothing. Just as if you had not specified any operand to the test.

In your first case, ($var double quoted) $var will still expand to nothing but within the double quotes, this incidentally providing the empty string "" as operand to the test.


Update following additional question from OP in comments :

why doesn't -n with no operand lead to, for example, "error: -n requires an operand"?

To which I had initially answered that, according to the manual, test

Exits with a status of 0 (true) or 1 (false)

With false including the case where "an invalid argument is given".

Some comment from illkachu provides a deeper insight :

A few test implementations (including Bash's) actually do return a distinct falsy status for an error, i.e. 0 for true, 1 for false and 2 for error

However :

It's just that both 1 and 2 are falsy as far as shell conditionals are concerned

The $ sign introduces parameter expansion, command substitution, or arithmetic expansion

In your second case ($var unquoted) since $var is empty, it will expand to nothing. Just as if you had not specified any operand to the test.

In your first case, ($var double quoted) $var will still expand to nothing but within the double quotes, this incidentally providing the empty string "" as operand to the test.

The $ sign introduces parameter expansion, command substitution, or arithmetic expansion

In your second case ($var unquoted) since $var is empty, it will expand to nothing. Just as if you had not specified any operand to the test.

In your first case, ($var double quoted) $var will still expand to nothing but within the double quotes, this incidentally providing the empty string "" as operand to the test.


Update following additional question from OP in comments :

why doesn't -n with no operand lead to, for example, "error: -n requires an operand"?

To which I had initially answered that, according to the manual, test

Exits with a status of 0 (true) or 1 (false)

With false including the case where "an invalid argument is given".

Some comment from illkachu provides a deeper insight :

A few test implementations (including Bash's) actually do return a distinct falsy status for an error, i.e. 0 for true, 1 for false and 2 for error

However :

It's just that both 1 and 2 are falsy as far as shell conditionals are concerned

edited body
Source Link
MC68020
  • 8.2k
  • 3
  • 19
  • 49

The $ sign introduces parameter expansion, command substitution, or arithmetic expansion

In your second case ($var unquoted) since $var is empty, it will expendexpand to nothing. Just as if you had not specified any operand to the test.

In your first case, ($var double quoted) $var will still expendexpand to nothing but within the double quotes, this incidentally providing the empty string "" as operand to the test.

The $ sign introduces parameter expansion, command substitution, or arithmetic expansion

In your second case ($var unquoted) since $var is empty, it will expend to nothing. Just as if you had not specified any operand to the test.

In your first case, ($var double quoted) $var will still expend to nothing but within the double quotes, this incidentally providing the empty string "" as operand to the test.

The $ sign introduces parameter expansion, command substitution, or arithmetic expansion

In your second case ($var unquoted) since $var is empty, it will expand to nothing. Just as if you had not specified any operand to the test.

In your first case, ($var double quoted) $var will still expand to nothing but within the double quotes, this incidentally providing the empty string "" as operand to the test.

deleted 3 characters in body
Source Link
MC68020
  • 8.2k
  • 3
  • 19
  • 49
Loading
Source Link
MC68020
  • 8.2k
  • 3
  • 19
  • 49
Loading