LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Closed Thread
  Search this Thread
Old 11-29-2008, 04:11 AM   #1
Lynda_M
LQ Newbie
 
Registered: Nov 2008
Posts: 3

Rep: Reputation: 0
Unhappy 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.
 
Old 11-29-2008, 05:02 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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.
 
Old 11-29-2008, 05:05 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
I just noticed that you crossposted this question: DON'T DO THAT!!! Read the rules before you start using this (or any) forum.
 
Old 11-29-2008, 08:03 PM   #4
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

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


Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
unary operator expected error! Lynda_M Programming 3 11-29-2008 12:04 PM
Unary operator error hinetvenkat Programming 7 10-26-2008 11:22 AM
unary operator expected MONKEYJUDO Linux - Newbie 1 07-13-2008 06:05 AM
Binary operator expected - error mike9287 Linux - Newbie 9 07-17-2006 08:27 AM
Unary Operator expected. Bash script Blackout_08 Programming 2 06-22-2006 02:21 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration