Skip to content

Instantly share code, notes, and snippets.

@chrissound
Created January 26, 2023 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrissound/762667fba754dc1a472a6386cca124f0 to your computer and use it in GitHub Desktop.
Save chrissound/762667fba754dc1a472a6386cca124f0 to your computer and use it in GitHub Desktop.
#!/bin/sh
string="abc\nxyz"
case $string in
(*[[:blank:]]*) echo "string contains at least one character classified as blank";;
(*[[:space:]]*) echo "string contains at least one character classified as whitespace (but not blank)";;
(*) echo no character classified as whitespace;;
esac
if [[ "$string" =~ [[:blank:]] ]]; then echo "Contains whitespace"; else echo "Doesn't contain whitespace"; fi
# the above outputs:
# no character classified as whitespace
# Doesn't contain whitespace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment