2

Having the following:

#!/usr/bin/env dash
seq -w 10 | while read -r num
do
    echo $num: $((num + 1))
done

prints

01: 2
02: 3
03: 4
04: 5
05: 6
06: 7
07: 8
sd: 3: sd: Illegal number: 08

Can anyone explain what is the problem with above dash artihmetic?

note, it is an dash (not bash) script.

Tagged it as bash too, for more attention from bash-experts too. :)

jub0bs
  • 60,866
  • 25
  • 183
  • 186
clt60
  • 62,119
  • 17
  • 107
  • 194
  • 1
    somewhat i forgot the octal numbers - it is same for `bash` too... really stupid question - have a bad day today.. ;( – clt60 Oct 13 '14 at 15:44

1 Answers1

5

Problem is leading 0 in your seq output that makes it an octal number and anything above 07 is an invalid octal number.

Note that this script will work fine without error:

seq 10 | while read -r num; do echo "$num: $((num + 1))"; done
anubhava
  • 761,203
  • 64
  • 569
  • 643