Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing infinite bash loop

Tags:

linux

bash

How to write an infinite loop echoing numbers from 1 to infinite in bash. I am using a for loop but it is being killed by bash on using value more than 100000000.

#!/bin/bash
for a in {1..100000000..1}
do
  echo "$a"
done

any alternative for it?

like image 248
Saqib Rao Avatar asked Mar 22 '26 00:03

Saqib Rao


1 Answers

Have you tried doing a while loop?

#!/bin/bash

num=0;

while :
do
    num=$((num+1))
    echo "$num"
done
like image 148
CristianHG Avatar answered Mar 24 '26 15:03

CristianHG



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!