[patch] bashism in sh script
GoTaR
gotar at poczta.onet.pl
Fri Aug 8 09:06:00 UTC 2003
On Fri, Aug 08, 2003 at 03:45:11 -0400, Pavel Roskin wrote:
> > There's no thing like $[..] to evaluate expressions in POSIX sh, it's
> > bash feature. sh uses $((..)) instead (and bash understands it too).
> > Here comes fix.
>
> Does the next line work for you? I mean this:
>
> if (( $A < 10 )); then A="0$A"; fi
Yes, it works. I cannot find appropriate info in SUS (no free access to
POSIX), so I don't know why. But it's supported by bash, zsh and pdksh
(all linked and called by /bin/sh too). The last one is supposed to be
POSIX-compliant, so if there's no problem with it, there should be no
problem with any other. The '<' operator is legal in expr.
> I think it's a much worse case of non-portable code.
So maybe change it to:
if [ $A -lt 10 ]; then A="0$A"; fi
or even
[ $A -lt 10 ] && A="0$A"
?
> Have you tested your changes?
Yes.
--
Tom Pala <gotar at pld-linux.org>
More information about the mc-devel
mailing list