Skip to content

Instantly share code, notes, and snippets.

@jmound
Last active October 17, 2023 15:28
Show Gist options
  • Save jmound/fb0d776ae1728f2084bc392df31dd7b8 to your computer and use it in GitHub Desktop.
Save jmound/fb0d776ae1728f2084bc392df31dd7b8 to your computer and use it in GitHub Desktop.
bash style guide- an example where it makes a difference
WITH_NEWLINE="line with newline
"
WITHOUT_NEWLINE="line without newline"
echo $WITH_NEWLINE
echo $WITHOUT_NEWLINE
echo "The above have matching newlines- you would expect that they should not"
echo "${WITH_NEWLINE}"
echo "${WITHOUT_NEWLINE}"
echo "The above don't have matching newlines, which is correct."
Output:
```
Users/jmound$ WITH_NEWLINE="line with newline
> "
Users/jmound$ WITHOUT_NEWLINE="line without newline"
Users/jmound$
Users/jmound$ echo $WITH_NEWLINE
line with newline
Users/jmound$ echo $WITHOUT_NEWLINE
line without newline
Users/jmound$ echo "The above have matching newlines- you would expect that they should not"
The above have matching newlines- you would expect that they should not
Users/jmound$
Users/jmound$ echo "${WITH_NEWLINE}"
line with newline
Users/jmound$ echo "${WITHOUT_NEWLINE}"
line without newline
Users/jmound$
```
The above commands don't exit with matching newlines, which is correct.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment