Created
March 18, 2016 17:08
-
-
Save wellsie/56a468a1d53527fec827 to your computer and use it in GitHub Desktop.
Function to determine if a string contains a space 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
#!/bin/bash -eux | |
function has-space { | |
[[ "$1" != "${1%[[:space:]]*}" ]] && return 0 || return 1 | |
} | |
if has-space "sadfsdf" ; then | |
echo "SPACE" | |
fi | |
if ! has-space "fassfsdgsdg" ; then | |
echo "NOSPACE" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment