bash problem when comparing integers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bash problem when comparing integers
# 1  
Old 02-20-2009
bash problem when comparing integers

Hi,

When I compare currentfiledate to reportfiledate I get a "-bash: [: 20090220080101: integer expression expected " error message.

currentfiledate=20090220080101
reportfiledate=20090219231245

if [ $currentfiledate -gt $reportfiledate ] ; then
echo -ne "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! \n"
echo -ne "!! Running the load utility !! \n"
fi

Our computer has a 64 bit processor, so I know it can handle the value in the variable.

What am I missing ?

Thank you.
# 2  
Old 02-20-2009
works fine under Solaris' "bash".
Does not work correctly under 'sh'.

Make sure you specify a desired shell interpreter in the first line of your script:
Code:
#!/bin/bash
currentfiledate=20090220080101
reportfiledate=20090219231245

if [ $currentfiledate -gt $reportfiledate ] ; then
   echo -ne "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! \n"
   echo -ne "!! Running the load utility !! \n"
fi

# 3  
Old 02-20-2009
Hi,

I had the statement in the program. Sorry, I did not paste it.

Here is more info about the bash version we're using :

>bash --version
GNU bash, version 2.05b.0(1)-release (powerpc-ibm-aix5.1.0.0)
Copyright (C) 2002 Free Software Foundation, Inc.

Thank you.
# 4  
Old 02-20-2009
ok, try this:
Code:
#!/bin/bash
#set -x
typeset -i currentfiledate=20090220080101
typeset -i reportfiledate=20090219231245

if [ $currentfiledate -gt $reportfiledate ] ; then
     echo -ne "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! \n"
     echo -ne "!! Running the load utility !! \n"
fi

# 5  
Old 02-20-2009
No....

Same error message :

bash: [: 20090220080101: integer expression expected
# 6  
Old 02-20-2009
hm.....
set the 'set -x' option and see what's being executed.
Also make sure there're no 'escape' characters in your script:
Code:
cat -vet myScriptFile.sh

Also, how exactly do you call/execute your script?
# 7  
Old 02-20-2009
Here is the output of the 'set -x' command :

+ typeset -i currentfiledate=20090220080101
+ typeset -i reportfiledate=20090219231245
+ '[' 20090220080101 -gt 20090219231245 ']'
./roger_eod_ofac.cfg: line 6: [: 20090220080101: integer expression expected

Here is the output of the 'cat -vet' command :

#!/usr/local/bin/bash$
set -x$
typeset -i currentfiledate=20090220080101$
typeset -i reportfiledate=20090219231245$
$
if [ $currentfiledate -gt $reportfiledate ] ; then$
echo -ne "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! \n"$
echo -ne "!! Running the load utility !! \n"$
fi$
$

I execute the program using the program name at the prompt 'roger_eod_ofac.cfg' also by preceding the program name with a period '. roger_eod_ofac.cfg'.

Thank you for helping...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Comparing Integers (I think)

Hi, I can't figure out what I'm missing. I'm running a query to see if there are any streams recording on my DVR before starting a scripted update. I'm guessing that it is viewing $VIDEO as a string instead of an int. I've tried everything I saw on google but it still comes back as $VIDEO is... (8 Replies)
Discussion started by: Rhysers
8 Replies

2. Shell Programming and Scripting

Bash - Comparing 2 xml strings masking certain fields

Would like to compare 2 XML Strings which has certain known fields changed. For example, Date field will always have differences. When comparing both strings, skip/mask all the occurring Date Field's `DtField1` and `DtField2` Note: these are not formatted xml format. File1: ... (1 Reply)
Discussion started by: Sajjadmehdi
1 Replies

3. Shell Programming and Scripting

Bash Integers/String

Hy friends, I am newbie to bash scripting, can anyone explain how b=${a/23/BB} # Substitute "BB" for "23". this line converts "b" into string and and "d" into Integer. Thanks in advance (4 Replies)
Discussion started by: Qazi
4 Replies

4. Shell Programming and Scripting

Grep float/integers but skip some integers

Hi, I am working in bash in Mac OSX, I have following 'input.txt' file: <INFO> HypoTestTool: >>> Done running HypoTestInverter on the workspace combined <INFO> HypoTestTool: The computed upper limit is: 11 +/- 1.02651 <INFO> HypoTestTool: expected limit (median) 11 <INFO> HypoTestTool: ... (13 Replies)
Discussion started by: Asif Siddique
13 Replies

5. Shell Programming and Scripting

Comparing time is bash

Hi, I have a question on comparing time using bash. Tried searching a lot up but couldn't figure it out. So I have this: CURRENT_TIME=$(date +%H:%M) if then echo "Continue" else echo "Quit" fi I tried a lot of different combinations of comparing, but nothing seems to work. Any help... (2 Replies)
Discussion started by: r4v3n
2 Replies

6. Shell Programming and Scripting

Comparing sizes in percentages of 2 files in bash

Hi guys, I hope you can enlight me with a script I'm doing for Solaris 10. Script goes like this: #!/usr/bin/bash fechahoy=`perl /export/home/info/John/fechamod.pl` fechayer=`perl /export/home/info/John/fecha.pl` echo $fechahoy echo $fechayer DAT1=`ssh ivt@blahblah ls -la... (1 Reply)
Discussion started by: sr00t
1 Replies

7. Shell Programming and Scripting

Editing lists of integers in 1d files with bash shell

Hi, I need a script that will: 1. Go through about 20 different folders, each containing about 20 1d files. The 1d files go something like this: 22.253 37.707 78.117 112.374 127.944 156.067 180.956 233.785 249.256 ... (1 Reply)
Discussion started by: ac130pilot
1 Replies

8. Shell Programming and Scripting

Help with comparing 2 lines in 2 different file in shell bash

Hi guys i need help with comparing lines in 2 separate files. Both files contain the same amount of lines and i need to output the difference into the 2nd file. The 1st file is always correct. 1st file (Expected.e): Tuesday, 11 August 2009 Wednesday, 12 August 2009 Thursday, 13 August 2009... (2 Replies)
Discussion started by: kcrap
2 Replies

9. Shell Programming and Scripting

comparing two arrays or strings in bash

Hi there, im having issue with comparing two variables, in a bash script. im trying to do the following: - get a word from user 1 - split the word into array - get a character from user2 trying to compare the character entered by user 2 with every single character in the array... (2 Replies)
Discussion started by: new2Linux
2 Replies

10. UNIX for Dummies Questions & Answers

Bash comparing date

Cound anyone help me on how to compare date in Unix using if function on bash file? current=date if ###syntax is wrong, could anyone correct it for me then rm -rf /usr/local/src fi Thank You... (17 Replies)
Discussion started by: Stanford Co
17 Replies
Login or Register to Ask a Question