I have a script like
#!/bin/bash
for i in {1..xx};do break="$i"
If....; then Some command
else break;fi
done
I need something which can repeat this script n times with incrementing $i.
I tried this:
For (( ; ; )); do i=1 && echo $i && ((i++));done
But this always shows 1, not an incrementing number. I also tried $((i+=1))
.
Where xx
is must be endless number.
Where break="$i"
gives me how many times repeated script.
Using for
to create an endless loop is unidiomatic, but not hard. Just make the ending condition never true; or, trivially, omit it.
for((i=0; ;++i)); do
echo "$i"
done
The above is Bash only. The usual solution, which works in POSIX sh
too, is to use while true
(but then that doesn't come with an incrementing index, if that's really what you need).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.