LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-08-2010, 01:48 PM   #1
learning78
LQ Newbie
 
Registered: Nov 2010
Posts: 3

Rep: Reputation: 0
Question NEWBIE ....need some help with "unary operator expected" error msg


if [ $games -gt 0 ] ; then
echo ""
echo "*** New Game! ***"
fi

this is the code that is producing the error, I am still in school and trying to get some assistance without going to my prof. The error msg is as follows:
[: -gt: unary operator expected
sed: -e expression #1, char 9: unterminated `s' command

why I am getting this I am not sure. I have tried "$games" but with no avail. Would really appreciate some assistance. Thx in advance
 
Old 11-08-2010, 02:31 PM   #2
penguiniator
Member
 
Registered: Feb 2004
Location: Olympia, WA
Distribution: SolydK
Posts: 442
Blog Entries: 3

Rep: Reputation: 60
Are you sure that $games is assigned a value prior to the test?
 
Old 11-09-2010, 01:42 AM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
Also, best practice is to double up on [ ] to [[ ]] ie http://tldp.org/LDP/abs/html/testcon...ml#DBLBRACKETS
 
Old 11-09-2010, 06:10 AM   #4
iamwilliam
Member
 
Registered: Apr 2006
Location: Nairobi
Distribution: CentOS
Posts: 78

Rep: Reputation: 21
Hi,

Noticed the following from your post
Quote:
[: -gt: unary operator expected
sed: -e expression #1, char 9: unterminated `s' command
it seems there's a sed command that fails as well. Correct syntax for sed would be
Code:
sed -e s/new/old/
 
Old 11-10-2010, 12:52 AM   #5
learning78
LQ Newbie
 
Registered: Nov 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Thank you guys very much I am going to made some adjustments and I'll let you know the fix. Thanks again. I think I'm gonna like it here on linuxquestions!
 
Old 11-10-2010, 01:46 PM   #6
learning78
LQ Newbie
 
Registered: Nov 2010
Posts: 3

Original Poster
Rep: Reputation: 0
so it turns out that I had accidentally commented out the declaration of games .....Thanks alot everyone I definitely got to spend alot of time debugging as I didnt notice that until the suggestion was made.
 
Old 11-11-2010, 01:21 AM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
This is great for debugging

set -xv

use after the #! line
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
error: unary operator expected ?? Lynda_M Programming 3 11-29-2008 09:03 PM
unary operator expected error! Lynda_M Programming 3 11-29-2008 01:04 PM
unary operator expected MONKEYJUDO Linux - Newbie 1 07-13-2008 07:05 AM


All times are GMT -5. The time now is 06:18 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration