Subscribe to our YouTube Channel for more Videos

How to find if a bash variable is empty?


If you want to know if a bash variable is empty , there are multiple ways to do it and this blog post explains how to do with the recommended way.

How to determine if a bash variable is empty?

if [ -z "${VAR}" ];

The above code snippet returns trus if a variable is unset (called null in programming terms) or if it is set to empty string.

Senthil Kumar B
Senthil Kumar is a former Microsoft MVP (Most Valuable Professional). He is a Co-Author of the book "Windows 10 Development Recipes using JavaScript and CSS" for Apress Publication. He is a technical presenter, blogger, mentor and a Geek.  Senthil is a regular speaker is various local user groups. He has presented at conferences like Great Indian Developer Summit (GIDS) & Microsoft DevCamps. You can reach out to him via his Twitter handle @isenthil.