Last active
October 17, 2023 15:28
-
-
Save jmound/fb0d776ae1728f2084bc392df31dd7b8 to your computer and use it in GitHub Desktop.
bash style guide- an example where it makes a difference
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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