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: John Kearney
Subject: Re: [Help-bash] Bug/limitation in 'time'
Date: Mon, 18 Mar 2013 21:15:46 +0100
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130307 Thunderbird/17.0.4

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]