i have a file called MYNAME in path /root/user/ which has some value say SSS_14_10_1992
when the values exists in file the below code works fine but when the file is empty , then the below mentioned error is thrown
i am reading this value from file and matching it wildcard and doing something , when the file has some value the below code works fine , when the file is empty then i am getting conditional error
Below is my code
var=$(cat /root/user/MYNAME)
echo $var
su - uname<<!
pwd
if [ -z "$var" ]; then
echo "NAME SHOULD BE PROVIDED IN MYNAME FILE"
else
if [[ $var == SSS_14_10* ]]
then
echo "value is matched"
else
echo "value has not matched"
fi
fi
!
when the file is empty i am getting the below error:
: conditional binary operator expected
: syntax error near `SSS_14_10*'
: ` if [[ == SSS_14_10* ]]'
var=$(cat /root/user/MYNAME)aftersu. Not sure if the variables defined for one user would withstand asucommand. I guess it doesn't.var=$(</root/user/MYNAME)SSS_14_10*(the*)? Use=~instead. (or is it~=?) . Good luck.