help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Bug/limitation in 'time'


From: Hans J Albertsson
Subject: Re: [Help-bash] Bug/limitation in 'time'
Date: Mon, 18 Mar 2013 22:00:15 +0100

With all this talk of portability, are there any systems around anywhere that dont sport bash?

Skickat från min Samsung Mobil



-------- Originalmeddelande --------
Från: John Kearney <address@hidden>
Datum:
Till: address@hidden
Rubrik: Re: [Help-bash] Bug/limitation in 'time'


Am 18.03.2013 13:31, schrieb Greg Wooledge:
On Mon, Mar 18, 2013 at 12:46:51AM -0700, Linda Walsh wrote:
To do the above, you'd want to pre-init
(I'd use i=${1:?"need start count"} in bash, but don't know if that is portable)

so, assuming I know i is > 0:
i=$1; while $((i-=1)); do :; done
The $((...)) expansion is not a command, so you can't use it after a
"while" or "if".  That's the role of ((...)) which, as already stated
several times in this thread, is *not* portable.

Personally, if I'm writing for POSIX sh, I'd do it this way:

i=$1
while [ $i -gt 0 ]; do
  i=$((i-1))
done

Of course that's assuming it makes sense to count downward in the script.
If you have to count upward for application reasons, then obviously do
it in reverse.


personally I do
i=$1
while [ $i -gt 0 ]; do
  : $((i-=1))
done
Correct me if I'm wrong but its just as portable and a little quicker. I think if memory serves.
Though I only really support pdksh and bash,



--
View John
          Kearney's profile on LinkedIn John Kearney

reply via email to

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