When i am comparing a blank variable with a string i am getting below error
[: !=: unary operator expected
Below is line in my script
if [ $monthlystatus = Completed ];then
command x
When i try to change this as below
if [ "$monthlystatus" = Completed ];then
command x
It does not give me expected result i.e. if statement give me wrong result. For example when i am using double quote and even the value of variable monthlystatus is equal to Completed but still command x is not executed.
Below is the real code .
if [ $monthlystatus != Failed ] && [ $monthlystatus != Aborted ];then
cat /home/a-hkataria/objectstatus_filesystem2.txt /home/a-hkataria/objectstatus_filesystem3.txt > /home/a-hkataria/objectstatus_filesystem4.txt
awk '$2 = $2 FS "Yes"' /home/a-hkataria/objectstatus_filesystem4.txt
else
cat /home/a-hkataria/objectstatus_filesystem2.txt /home/a-hkataria/objectstatus_filesystem3.txt > /home/a-hkataria/objectstatus_filesystem4.txt
awk '$2 = $2 FS "No"' /home/a-hkataria/objectstatus_filesystem4.txt
fi
So in case variable monthlystatus
is blank it is giving me error and when i use the double quote even value of variable is Completed
but still it is not displaying yes
in second column.