The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
[: =: unary operator expected bhag281 UNIX for Dummies Questions & Answers 7 03-10-2009 09:47 AM
unary operator expected Satyak Shell Programming and Scripting 2 03-06-2009 02:56 PM
awk returning "[: ==: unary operator expected" theamrit Shell Programming and Scripting 2 11-03-2008 01:51 PM
unary operator expected error ssuresh1999 UNIX for Dummies Questions & Answers 2 10-28-2008 09:33 PM
Binary operator expected basisvasis Shell Programming and Scripting 4 09-26-2008 04:33 PM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 04-03-2009
timgolding timgolding is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 34
unary operator expected

Im trying to fix my /etc/weekly that rotates various logs however it does them no matter what filesize they are and i want them to only do it if there file size exceeds 2M or something. So I'm playing with a script to get the filesize using a ls -l command which works and puts the value into a variable.

So then i hope to test that variable with if -gt but it doesn't work, maybe because its the wrong data type not sure really. Here is the code I'm playing with

Code:
ls -l asl.log| awk '{printf "%s",$5}'
max=300
if [ $5 -gt $max ]; then echo "wohoo";
else echo "grr";
fi

I have checked the result of

Code:
ls -l asl.log| awk '{printf "%s",$5}'
It is greater than 300. But when i run this script the condtion is returning false and i get an error here is the output when running the script

Quote:
93452560
test.sh: line 5: [: -gt: unary operator expected
grr
WebServer:/home/scripts timgolding$
I hope someone can help before i loose my hair
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This 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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:29 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0