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: Greg Wooledge
Subject: Re: [Help-bash] Bug/limitation in 'time'
Date: Mon, 18 Mar 2013 08:31:54 -0400
User-agent: Mutt/1.4.2.3i

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.



reply via email to

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