I have a script in which I have a line which does put the third line fetched in my variable like this:
variable=`sed -n '3 p' /home/nmsadm/abc.txt`
So variable holds this value Which is in third line of abc.txt. In my case it
will be a one word line or an empty/blank line.
How can I compare the variable in a shell script to know if it’s an empty/blank line?
echo $variable fetched me an empty line.
What is the comparison i need to here so that
I am assured it’s an empty line? Something like this:
if [ "$variable" = "comparison" ]; then
Empty or undefined:
Single newline:
Undefined:
Note, the last command is not the opposite of
To see why, try running
variable=undefinedfirst."${variable+defined}"has only two possible values: The empty string ordefined.