It is currently Tue, 07 Dec 2021 02:50:05 GMT

Author Message
 ksh/bash: let cmd and test cmd interpret 08 (octal) differently
Beneath issue tested on Linux with bash and Solaris with ksh. I retrieve
current day using date +%d which always returns a two digits string. Which
means a leading zero for days 1 to 9. In (bash) shell this means interpret
number as an octal number.

day=`date +%d`
let day=${day}+1.
Suppose its day 8 (string is 08).  An error occurs --> let: day=08: value
too great for base (error token is "08").  Seems valid. Range for the octal
number is from 0 to 7.
Remark: let day=${day#0}+1. Is ok too. The string operator removes leading 0
before doing the addition.

No problems so far. Now my question. I can't explain behaviour of the
beneath code.

if [ ${month} -eq 08 ]; then
    echo "match found"
Running prog results in "match found".  Same for "if test  ${month} -eq 08"
or a if [ ${month} -eq 8 ];  (no leading zero).

I thought the 08 should be interpreted as an octal number (to be precise as
an illegal octal number) and create an error. It seems the shell
interpreteds number as DECIMAL here. Strange, can't explain....

Its no matter of life and death. It just bugs me that I can't figure it
out... Any help/pointers is very much appreciated as is an email on

Jan Bessels

 Sat, 26 Jun 2004 17:36:18 GMT   
   [ 1 post ] 

Similar Threads

1. backup CMD VS. savevg CMD

2. Remapping bash cmd-edit keys?

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software