Bash shell find out if a variable has NULL value OR not

Originally published at:

I am a new to shell scripting. How do I check for NULL value in a Linux or Unix shell scripts?

You can use this way:

if [[ ${my_str} ]]; then
  echo " Has a value"
  echo "No value"
1 Like

This would have worked:

[ "$my_str" ] && echo Has a value || echo No value