Shell – What are some cases that the number of spaces do matter in bash (or other shell) scripts

shellshell-script

I have been told that the spaces are important in bash or other shell scripts and I should not change the existence of spaces unless I know what I am doing. By "changing the existence" I mean either inserting a space between two non-space characters or removing a space between two non-space characters, e.g. changing var="$val" to var ="$val" or vice versa.
I want to ask

Are there any cases in which using a single space or using multiple consecutive spaces in a shell script makes a difference?.

(Of course, inserting/deleting a space in quotes makes a difference ,like changing from echo "a b" to echo "a b" or vice versa. I am looking for examples other than this trivial example.)

I have come across this question but that one is about adding and removing spaces between two non-space characters for which I know many examples that it would make a difference.

Any help would be appreciated. Include more varieties of shells if possible.

Best Answer

Outside of quotes, the shell uses whitespace (spaces, tabs, newline, carriage-return, etc) as a word/token separator. That means:

  • Things not separated by whitespace are considered to be one "word".
  • Things separated by one-or-more whitespace characters are considered to be two (or more) words.

The actual number of whitespace chars between each "thing" doesn't matter, as long as there is at least one.