Skip to content

Instantly share code, notes, and snippets.

@dryliketoast
Last active September 11, 2015 16:26
Show Gist options
  • Save dryliketoast/7ca004ec77d4e3cd6a21 to your computer and use it in GitHub Desktop.
Save dryliketoast/7ca004ec77d4e3cd6a21 to your computer and use it in GitHub Desktop.
line returns in bash
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