Linux.com

Author Message
Joined: Nov 29, 2008
Posts: 1
Other Topics
Posted Nov 29, 2008 at 9:14:57 AM
Subject: unary operator expected error???
Hi everyone, I'm new to Linux Shell scripting 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.
Back to top Profile Email Website
thobbs
Joined Oct 12, 2008
Posts: 238
Location:Texas!

Other Topics
Posted: Nov 29, 2008 4:52:43 PM
Subject: unary operator expected error???
$USERNAME may be empty (it shouldn't, but the computer doesn't know that). You need to put $USERNAME in double qoutes, like this: [code=xml]if [ "$USERNAME" != "root" ][/code] That way, when "$USERNAME" is expanded to a String (because you are doing a String comparison), if it's empty, you'll at least have an empty "". [Modified by: thobbs on November 29, 2008 10:53 AM]
Back to top Profile Email Website
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya