Skip to main content
edited tags
Link
Gilles 'SO- stop being evil'
  • 865.4k
  • 205
  • 1.8k
  • 2.3k
deleted 4 characters in body
Source Link
Hauke Laging
  • 94.6k
  • 21
  • 132
  • 185

Can we use bash's conditional operator with assignment operators after colon?

Bash reference manual explains the arithmetic operators as follows.

  • conditional operator expr ? expr : expr
  • assignment = *= /= %= += -= <<= >>= &= ^= |=

FisrtFirst, this code seems to work well.:

a=1; ((a? b=1 : 2 )) #seems to work

a=1; ((a? b=1 : 2 )) #seems to work

But when I use assignment operators after :, I got 'attempted assignment to non-variable' error.:

a=1; ((a? b=1 : c=1)) #attempted assignment to non-variable error

a=1; ((a? b=1 : c=1)) #attempted assignment to non-variable error

Why can we use only assignment operators before colon?

Can we use bash's conditional operator with assignment operators after colon?

Bash reference manual explains the arithmetic operators as follows.

  • conditional operator expr ? expr : expr
  • assignment = *= /= %= += -= <<= >>= &= ^= |=

Fisrt, this code seems to work well.

a=1; ((a? b=1 : 2 )) #seems to work

But when I use assignment operators after :, I got 'attempted assignment to non-variable' error.

a=1; ((a? b=1 : c=1)) #attempted assignment to non-variable error

Why can we use only assignment operators before colon?

Can we use bash's conditional operator with assignment operators after colon?

Bash reference manual explains the arithmetic operators as follows.

  • conditional operator expr ? expr : expr
  • assignment = *= /= %= += -= <<= >>= &= ^= |=

First, this code seems to work well:

a=1; ((a? b=1 : 2 )) #seems to work

But when I use assignment operators after :, I got 'attempted assignment to non-variable' error:

a=1; ((a? b=1 : c=1)) #attempted assignment to non-variable error

Why can we use only assignment operators before colon?

added 2 characters in body
Source Link
MS.Kim
  • 1.7k
  • 4
  • 18
  • 18

Can we use bash's conditional operator with assignment operators like thisafter colon?

Bash reference manual explains the arithmetic operators as follows.

  • conditional operator expr ? expr : expr
  • assignment = *= /= %= += -= <<= >>= &= ^= |=

Fisrt, this code seems to work well.

a=1; ((a? b=1 : 2 )) #seems to work

But when I use assignment operatoroperators after :, I got the attempted'attempted assignment to non-variablevariable' error.

a=1; ((a? b=1 : c=1)) #attempted assignment to non-variable error

Why we can we use only assignment operators before colon?

Can we use bash's conditional operator with assignment operators like this?

Bash reference manual explains the arithmetic operators as follows.

  • conditional operator expr ? expr : expr
  • assignment = *= /= %= += -= <<= >>= &= ^= |=

Fisrt, this code seems to work well.

a=1; ((a? b=1 : 2 )) #seems to work

But when I use assignment operator after :, I got the attempted assignment to non-variable error.

a=1; ((a? b=1 : c=1)) #attempted assignment to non-variable error

Why we can use only assignment operators before colon?

Can we use bash's conditional operator with assignment operators after colon?

Bash reference manual explains the arithmetic operators as follows.

  • conditional operator expr ? expr : expr
  • assignment = *= /= %= += -= <<= >>= &= ^= |=

Fisrt, this code seems to work well.

a=1; ((a? b=1 : 2 )) #seems to work

But when I use assignment operators after :, I got 'attempted assignment to non-variable' error.

a=1; ((a? b=1 : c=1)) #attempted assignment to non-variable error

Why can we use only assignment operators before colon?

deleted 7 characters in body
Source Link
MS.Kim
  • 1.7k
  • 4
  • 18
  • 18
Loading
Source Link
MS.Kim
  • 1.7k
  • 4
  • 18
  • 18
Loading