Last active
September 11, 2015 16:26
-
-
Save dryliketoast/7ca004ec77d4e3cd6a21 to your computer and use it in GitHub Desktop.
line returns in bash
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 bash, if you want to embed newlines in a string, enclose the string with $'': | |
$ list="One\ntwo\nthree\nfour" | |
$ echo "$list" | |
One\ntwo\nthree\nfour | |
$ list=$'One\ntwo\nthree\nfour' | |
$ echo "$list" | |
One | |
two | |
three | |
four | |
And if you have such a string already in a variable, you can read it line-by-line with: | |
while read -r line; do | |
echo "... $line ..." | |
done <<< "$list" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment