Terminal check if string has value
 
  January 5, 2020

A basic task when you are scripting is to verify if a string is empty or not. We can do it using the following operators -n y -z

 Check if empty

            

#!/bin/bash

VAR=''
if [[ -z $VAR ]]; then
echo "String is empty."
fi
            
            
        

 Check if not empty

            

#!/bin/bash

VAR='Linuxize'
if [[ -n $VAR ]]; then
echo "String is not empty."
fi
            
            
        

REFERENCE: Linuxize