LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   error: unary operator expected ?? (https://www.linuxquestions.org/questions/programming-9/error-unary-operator-expected-687025/)

Lynda_M 11-29-2008 04:11 AM

error: unary operator expected ??
 
Hi everyone,
I'm a Linux newbie and would appreciate any help solving my issue...
I'm running a script to set up Linux OS environment, the script works great but i get an error on the following portion:

if [ $USERNAME != "root" ]
then
echo "Cannot proceed with setup.You must be logged in as root!"
exit
else
proc=m
while [ $proc != "y" -a $proc != "Y" -a $proc != "n" -a $proc != "N" ]
do
echo -n "Are you ready to proceed?(Y/N)"
read proc
if [ $proc == "n" -o $proc == "N" ]
then
exit
else
if [ $proc == "y" -o $proc == "Y" ]
then
continue
fi
fi
done
fi

The error i get:
line:2 [: !=: unary operator expected.
But the script continues to run...
Any help eliminating that error please!
Thanks in advance.

druuna 11-29-2008 05:02 AM

Hi,

Is there the possibility that $USERNAME is empty?

If that is the case then if [ $USERNAME != "root" ] will resolve to if [ != "root" ], which will throw the error shown by you.

Put quotes around the variable to solve this: if [ "$USERNAME" != "root" ].

Hope this helps.

druuna 11-29-2008 05:05 AM

I just noticed that you crossposted this question: DON'T DO THAT!!! Read the rules before you start using this (or any) forum.

crabboy 11-29-2008 08:03 PM

Closing, duplicate of: http://www.linuxquestions.org/questi...-error-687011/


All times are GMT -5. The time now is 12:28 AM.