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

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

$
0
0

Not an exact answer, but ran into this trick. If the string you're looking for comes from "a command" then you can actually store the command in an env. variable and then execute it every time for the if statement, then no brackets required!

For example this command, which determines if you're on debian:

grep debian /proc/version

full example:

IS_DEBIAN="grep -i debian /proc/version"

if $IS_DEBIAN; then
  echo 'yes debian'
else
  echo 'non debian'
fi

So this is like an indirect way (rerunning it every time) to check for an empty string (it happens to be checking for error response from the command, but it also happens to be returning an empty string).


Viewing all articles
Browse latest Browse all 16

Trending Articles



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