LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-18-2012, 02:51 PM   #1
jnojr
Member
 
Registered: Sep 2007
Location: Chandler, AZ
Posts: 227

Rep: Reputation: 20
Unary operator expected


In all my Googling, this usually happens when someone is comparing a variable, and that variable is unset. That doesn't appear to be the case for me...

Code:
#!/bin/bash -x

  while read line
  do
    f=$(echo $line | tr -s ' ' | cut -d' ' -f 3)
    echo $f
    if [ "$f" >= 500 ]
    then
      echo "This is a finding"
      echo $i
    fi
  done < /tmp/ls.txt
Result:

Code:
+ read line
++ echo drwxr-xr-x@ 39 0 0 1326 Oct 1 14:01 .
++ tr -s ' '
++ cut '-d ' -f 3
+ f=0
+ echo 0
0
+ '[' 0 500 ']'
./test.sh: line 15: [: 0: unary operator expected
It seems to be tossing my ">=" away.
 
Old 10-18-2012, 04:20 PM   #2
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
I think bash does not like the >= operator inside brackets. It should be
Code:
if [ "$f" -ge 500 ]
or, slightly better
Code:
if [[ "$f" -ge 500 ]]
or, even better
Code:
if (( f >= 500 ))
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
-ge: unary operator expected daisychick Linux - Software 8 09-17-2012 12:56 AM
[SOLVED] -gt: unary operator expected hd_pulse Programming 10 05-28-2011 07:57 AM
[SOLVED] unary operator expected hd_pulse Programming 8 05-26-2011 11:01 PM
unary operator expected error! Lynda_M Programming 3 11-29-2008 12:04 PM
unary operator expected MONKEYJUDO Linux - Newbie 1 07-13-2008 06:05 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:56 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