Created
July 4, 2014 16:37
-
-
Save zmwangx/16ac4697a6d75213fca8 to your computer and use it in GitHub Desktop.
Bash: test for newline in a string.
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
#!/bin/bash | |
# Use pattern matching: http://goo.gl/q6qNco. | |
# The newline in the pattern string needs to be quoted. | |
# See ANSI-C quoting: http://goo.gl/I3HZTR | |
string=$(echo -e 'hello\nworld') | |
if [[ ${string} == *$'\n'* ]]; then | |
echo 'newline detected' >&2 | |
else | |
echo 'newline not detected' >&2 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment