4

I have the following script that extracts data from the EXIF command on my busybox ash-based system. I parse the date tag from the end of the file and use case as a final check to ensure the format is correct. My problem is the if statement at the end always seems to return true; i.e. d="$e - Jebby (exif" always runs. If I echo $en and echo $dn it shows $en is greater than $dn but the if statement still runs the d="$e - Jebby (exif".

x=<valid filename>
e=$(exif -d -m -t 0x9003 -- "$x" 2>/dev/null)
let l=${#e}-18
e=$(expr substr "$e" $l 19)
e="${e%[ ][0-2][0-9][:][0-6][0-9][:][0-6][0-9]*}" 
e="${e##*[!1-2][!09][!0-9][!0-9][!:][!0-1][!0-9][!:][!0-3][!0-9]}"
e=$(expr substr "$e" 1 4)$(expr substr "$e" 6 2)$(expr substr "$e" 9 2)
case "$e" in 
   [1-2][09][0-9][0-9][0-1][0-9][0-3][0-9])
     let en=$e+3
     ds="${d% - Jebby (}"
     let dn=$ds
     if [ $en -lt $dn ]; then
        d="$e - Jebby (exif"
     fi
esac

closed as unclear what you're asking by Michael Mrozek Sep 12 '17 at 20:24

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Are you sure you're using ash, not bash or some other shell? AFAIK ash has no let built in. – terdon Jan 19 '14 at 15:25
  • It is a Synology NAS running busybox which my understanding is close to ash shell. Let is present but declare is not. – Wags Jan 19 '14 at 16:48
  • 1
    Ah, OK, my local version of ash gives various error messages when trying to run your code so I can't really test. You should probably quote the variables you are comparing: if [ "$en" -lt "$dn" ]; – terdon Jan 19 '14 at 16:50
  • I don't know what ds="${d% - Jebby (}" is supposed to expand to, but when you assign that value to dn, it doesn't look like a number, so the numeric lt` comparison fails in unexpected ways. Echo out the values of $en and $dn for a failing case to confirm. – Jeff Schaller Aug 8 '16 at 1:29
  • 1
    @agc busybox is a multicall binary which is its own ash. Just take the binary from the link above and run ./busybox ash. – michas Dec 3 '16 at 13:52
1

For me comparison in ash works fine:

./busybox ash
$ [ 1 -lt 2 ] && echo true || echo false
false
$ [ 3 -lt 2 ] && echo true || echo false
true
$ a=1 b=2 c=3
$ [ $a -lt $b ] && echo true || echo false
true
$ [ $c -lt $b ] && echo true || echo false
false
$ 

What exactly is the content of your variables? You are aware that -lt compares numerically?

You might also do set -x to see what is going on.

  • On my BusyBox v1.22.1 the first one actually returns true and the second false ("1 less than 2" is supposed to be truthy, i.e. zero). On an unrelated note, sad to see this question closed because it is genuinely helpful. – Norrius Dec 12 '18 at 18:33

Not the answer you're looking for? Browse other questions tagged or ask your own question.