bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Octal numbers and backward incompatibility with Bourne shell


From: Aleksandar Milivojevic
Subject: Octal numbers and backward incompatibility with Bourne shell
Date: 01 Aug 2002 09:13:46 +0200
User-agent: Gnus/5.090002 (Oort Gnus v0.02) XEmacs/21.1 (Biscayne)

I'v found something that I think should be considered as bug.

Somebody added support for octal numbers into bash, and thus made it
backward incompatible with Bourne and Korn shells.

For example, consider following simple shell script (needs ksh or
POSIX sh because of arithemtics):

===== 8< Cut Here 8< =====
#!/bin/sh

cur_year="`date '+%Y'`"
cur_month="`date '+%m'`"
cur_month="$(($cur_month - 1))"
if [ "$cur_month" == "0" ]
then
  cur_month="12"
  cur_year="$((cur_year - 1))"
fi
if [ "$cur_month" -lt "10" ]
then
  cur_month="0$cur_month"
fi

echo "$cur_month" "$cur_year"
===== 8< Cut Here 8< =====

On every single POSIX compliant sh implementation I'v tryed so far it
prints out previous month.  Except on Linux (Linux uses bash to
implement sh) where it gives an error in third line.

This imcompatibility broke my shell script (it is August today, date
gives "08" for month) and has the potential of breaking many others
that depend on the simple fact that Bourne shell (as well as Korn
shell) doesn't know anything about octal numbers.  In Bourne/Korn
shell "08" is 8.  Simple as that.  It isn't C language, it is shell
script.  Please, if you add such features, make them optional (for
example by using --octal or whatever option).

-- 
Aleksandar Milivojević <address@hidden>
Opinions expressed herein are my own.
Statements included here may be fiction rather than truth.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]