![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Use this logic
Code:
maximum=`cat file1.txt|head -1|awk '{print $1}'`
[ -z $maximum ] && max=0 || max=$maximum
echo $max
|
|
#3
|
|||
|
|||
|
Try this
max=${maximum:-0}
if maxinum is not blank it will assing 0, otherwise it will assign value of $maxinum |
|||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|