Re: [patch] bashism in sh script



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 pld-linux org>



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