Comment Re:I'll bite (Score 1) 265
Because there's no such thing as an assignment operator in bash. Everything is a string token at first (even numbers aren't number unless you're in arithmetic evaluation context), and then tokens get interpreted in various ways once split by whitespace.
x = 3 happens to be three tokens, the first one being the command 'x', the other two being parameters '=' and '3' to command 'x'.
x=3 is one token and it doesn't mean assignment unless it's in the command preface where assignments take place.
This is from 'man bash', under SHELL GRAMMAR / Simple Commands:
A simple command is a sequence of optional variable assignments followed by blank-separated words and redirections, and terminated by a control operator. The first word specifies the command to be executed, and is passed as argument zero. The remaining words are passed as arguments to the invoked command.
The AC failed to recognise the $(command) construct, which is 'execute this command and give me its output as a string.
And the AC also messed up the arithmetic. This is what should have been written:
x=$((x+1))
This three are even better:
((x = x + 1))
((x += 1))
((x++))
Variable expansion happens in the arithmetic context (see 'man bash' / EXPANSION / Arithmetic Expansion), so doing $(($x + 1)) is actually wrong, because if $x expands to 'y' then you end up with $((y + 1)), which might be useful sometimes, but given the lack of understanding shown it's probably not what you're actually trying to do.
RTFM means 'man bash' in this case. It may take you a day to go through it and experiment with what you learn in each section, but it's worth it.