Quantcast
Channel: How to determine if a bash variable is empty? - Server Fault
Viewing all articles
Browse latest Browse all 16

Answer by Raman Kathpalia for How to determine if a bash variable is empty?

$
0
0

To figure out if a variable "Foo" is empty and also contains no spaces (or no whitespace as some people refer it).

 if [[ -n "${Foo/[ ]*\n/}" ]];then    echo "Foo is not empty and contains non space characters"fi# Another way to solve the same problem: Take spaces out in Foo & check if Foo is empty if [[ -z "${Foo// }" ]];then     echo "Foo is empty" fi

Viewing all articles
Browse latest Browse all 16

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>