Skip to content

Instantly share code, notes, and snippets.

@wellsie
Created March 18, 2016 17:08
Show Gist options
  • Save wellsie/56a468a1d53527fec827 to your computer and use it in GitHub Desktop.
Save wellsie/56a468a1d53527fec827 to your computer and use it in GitHub Desktop.
Function to determine if a string contains a space in bash
#!/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