The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
passing variable from bash to perl from bash script arsidh Shell Programming and Scripting 10 06-04-2008 09:25 AM
Bash Script error? JayC89 Shell Programming and Scripting 13 10-04-2007 01:32 PM
error in bash script 'if' loop DILEEP410 Shell Programming and Scripting 2 06-06-2007 05:04 AM
error checking in bash gubten Shell Programming and Scripting 3 06-06-2006 01:38 PM
Bash installation error c19h28O2 UNIX for Dummies Questions & Answers 0 04-13-2006 05:08 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-22-2008
Registered User
 

Join Date: Nov 2007
Posts: 131
Help in error seen in the Bash script

Hi,

I am currently encounter an error of:-
./max.bash: line 45: [: 0.226667: integer expression expected

Basically I try to get the first field of first element in a file. If the first field number does not return me anything from the file, i will set the variable max as 0.

maximum=`cat $version.txt|head -1|awk '{print $1}'`

if [ $maximum -eq 0 ]
then
max=0
else
max=$maximum

It seems that it does not allow max to assigned with floating numbers.

Please help.


Thanks.
Reply With Quote
Forum Sponsor
  #2  
Old 01-22-2008
jaduks's Avatar
Registered User
 

Join Date: Aug 2007
Location: Assam,India
Posts: 146
Use this logic

Code:
maximum=`cat file1.txt|head -1|awk '{print $1}'`

[ -z $maximum ] && max=0 || max=$maximum
echo $max
//Jadu
Reply With Quote
  #3  
Old 01-22-2008
Registered User
 

Join Date: Nov 2007
Posts: 85
Try this

max=${maximum:-0}

if maxinum is not blank it will assing 0, otherwise it will assign value of $maxinum
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:28 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0