You can stop and put your job in background while it's running using ctrl+z. Then you can kill your job with:

$ kill %1

Where [1] is your job number.

Answer from Jem on Stack Exchange
🌐
nixCraft
cyberciti.biz › nixcraft › howto › bash shell › bash infinite loop examples
Bash Infinite Loop Examples - nixCraft
February 3, 2025 - This is a loop that will forever print “Press [CTRL+C] to stop..”. Please note that : is the null command. The null command does nothing and its exit status is always set to true.
People also ask

How do you make an infinite loop in Bash?
To make an infinite loop in Bash, use a for or while loop with true as a constant loop condition. Thus, the loop runs infinitely until it is explicitly interrupted.
🌐
linuxsimply.com
linuxsimply.com › home › bash scripting tutorial › loops in bash › for loop in bash › how to create infinite loop in bash [7 cases]
How to Create Infinite Loop in Bash [7 Cases] - LinuxSimply
How do I exit a Bash loop?
You can exit a Bash loop by using the break statement. This is a loop control statement that terminates a loop and moves to execute the subsequent commands after the loop.
🌐
linuxsimply.com
linuxsimply.com › home › bash scripting tutorial › loops in bash › for loop in bash › how to create infinite loop in bash [7 cases]
How to Create Infinite Loop in Bash [7 Cases] - LinuxSimply
How do you break an infinite loop?
To break an infinite loop, press CTRL+C on the keyboard. It will send a signal to interrupt the execution of the loop, which is running indefinitely.
🌐
linuxsimply.com
linuxsimply.com › home › bash scripting tutorial › loops in bash › for loop in bash › how to create infinite loop in bash [7 cases]
How to Create Infinite Loop in Bash [7 Cases] - LinuxSimply
🌐
CyberCiti
bash.cyberciti.biz › guide › Infinite_while_loop
Infinite while loop - Linux Bash Shell Scripting Tutorial Wiki
#!/bin/bash # set an infinite loop while : do clear # display menu echo "Server Name - $(hostname)" echo "-------------------------------" echo " M A I N - M E N U" echo "-------------------------------" echo "1. Display date and time." echo "2. Display what users are doing." echo "3.
🌐
Linux Hint
linuxhint.com › creating-bash-infinite-loop-by-example-scripts
Creating Bash Infinite Loop by Example Scripts – Linux Hint
The while loop is closed with the “done” keyword. while true do echo "Do some task; Press [CTRL+C] to stop!" done · At the time of the execution, we opened the terminal and ran the bash command “./bash1.sh”. When the bash file is executed, it runs endlessly and prints the echo command infinitely in the terminal.
🌐
FOSS Linux
fosslinux.com › home › learn linux › bash for loop with practical examples
Bash For Loop with practical examples | FOSS Linux
June 15, 2020 - To get out of an infinite loop, press Ctrl + C to cancel the process. In programming, the Break and Continue statements control the execution of a program. The Break statement terminates the program and gets out of the Loop.
Find elsewhere
🌐
iO Flood
ioflood.com › blog › bash-infinite-loop
Creating an Infinite Bash Loop: Linux Shell Script Syntax
December 4, 2023 - In this example, we’ve used the ‘while’ loop with the condition set to ‘true’. This means the loop will keep running and echoing ‘This is an infinite loop’ until it’s explicitly stopped by the user. But Bash’s infinite loop capabilities go far beyond this.
🌐
Spiceworks
community.spiceworks.com › software & applications
Create Infinite Loop In Bash - Software & Applications - Spiceworks Community
April 20, 2020 - I want to run a command for ever in the Linux bash. Also I want to put 60 seconds between command execution.
🌐
LinuxSimply
linuxsimply.com › home › bash scripting tutorial › loops in bash › for loop in bash › how to create infinite loop in bash [7 cases]
How to Create Infinite Loop in Bash [7 Cases] - LinuxSimply
March 17, 2024 - To create an infinite loop in Bash, select the while loop and keep the loop condition true. It is a structure that repeats a set of commands indefinitely. It tirelessly continues as long as the loop remains uninterrupted.
🌐
Linuxize
linuxize.com › home › bash › bash while loop: syntax and examples
Bash while Loop: Syntax and Examples | Linuxize
February 27, 2026 - An until loop runs as long as the condition is false — it is the logical opposite of while. How do I exit an infinite while loop? From the terminal, press CTRL+C to interrupt the loop.
🌐
Network World
networkworld.com › home › blogs › unix as a second language
How to loop forever in bash | Network World
February 27, 2025 - Of course, you’re not ever going to want to loop forever, but having loops run until you stop them can often be very useful. The script below runs until 5:00 p.m. It uses the date command with the +%H option to check the time, then reminds you that it’s time to go home and exits. The sleep 60 command was included to limit the time checking to once a minute. Otherwise, this script could gobble up a lot of CPU time. #!/bin/bash while true do if [ `date +%H` -ge 17 ]; then echo Time to go home exit # exit script else sleep 60 fi done
🌐
LabEx
labex.io › tutorials › linux-how-to-stop-bash-script-infinite-loop-435107
How to stop bash script infinite loop | LabEx
An infinite loop is a sequence of instructions in a bash script that repeats indefinitely because the loop's termination condition is never met.
Top answer
1 of 2
6

How to run a infinite_number_loop in bash?

The easy way: while :; do ... done:

let i=0
while :; do
    let i++
    date +%Y-%m-%d -d "$i day ago" >/dev/null 2>&1 || { echo $i && exit 1; }
done

If I run this loop in terminal in my local machine, is there any issue?

Not until you realize you wasted too much time on this.

2 of 2
1

Not an infinite loop, but a better way to find the actual limit of date:

#!/bin/bash

j=$((1<<61))
i=0
while ((j>0)); do
    if date +'%Y-%m-%d' -d "$((i+j)) days ago" >/dev/null 2>&1; then
    ((i+=j)) ; # printf 'running i %d 0x%x\n' "$i"{,}
    else
    ((j>>=1)); # printf 'new     j %d 0x%x\n' "$j"{,}
    fi
    ((k++))
    # ((k%10)) || printf 'still running %d 0x%x %d %d' "$i"{,} "$j" "$k"
done
printf "final value of limit %d 0x%x in %d loops\n" "$i"{,} "$k"

That will find the limit of date to be:

final value of limit 2147483649 0x80000001 in 64 loops

Remove the comment character # to see how that is done.

It is not a 32 bit number.

That seem to be close to a 32 bit number:

$ printf '%d\n%d\n' "$(( (1<<31) + 1 ))" "0x80000001"
2147483649
2147483649

In fact, is 2**31 + the day number of the month.
If we try with the last day in December (change line 5 in the script above):

date +'%Y-%m-%d' -d "2017-12-31 $((i+j)) days ago"

We get:

final value of limit 2147483679 0x8000001f in 68 loops

That's 31 above 2**31:

$ printf '%d\n%d\n' "$(( (2**31) + 31 ))" "0x8000001f"
2147483679
2147483679

It is also affected by the time zone.

Arithmetic notes

The max value for a shell integer is i less than 2 raised to 63:

$ echo $(( (2**63) - 1 ))
9223372036854775807

We can get the decimal and hexadecimal representation with:

$ printf '%d %x\n' "$(( (2**63) - 1 ))"{,}
9223372036854775807 7fffffffffffffff

That's the maximum number representable in a signed integer of 64 bits (if your system is 64 bits, of course). The next number (just add one) will wrap around (overflow) to a negative number:

$ echo $(( (2**63) ))
-9223372036854775808

$ printf '%d %x\n' "$(( (2**63) ))"{,} 
-9223372036854775808 8000000000000000

Which happens to be the most negative number for signed 64 bit integer.

But a faster way to get the same result is using left shift, which does the same as multiplying a number by two:

$ printf '%d %x\n' "$(( (1<<63) - 1 ))"{,}
9223372036854775807 7fffffffffffffff
🌐
Ask Ubuntu
askubuntu.com › questions › 1256326 › infinite-loop-when-trying-to-launch-a-symbolic-link-to-a-bash-script
command line - Infinite loop when trying to launch a symbolic-link to a bash script - Ask Ubuntu
Your script trims .sh so running it from foo.sh gets you "No such file...", but then you run it as foo nothing get trimmed and you get an infinite loop.
🌐
LinuxSimply
linuxsimply.com › home › bash scripting tutorial › loops in bash › "while" loop in bash › one line infinite “while” loop in bash [4 examples]
One Line Infinite “while” Loop in Bash [4 Examples] - LinuxSimply
March 31, 2024 - The until loop executes a set of tasks repeatedly as long as the loop condition remains false. To create an infinite until loop, put false inside the loop condition. Here is a one-line bash command to print a message continuously:
🌐
Super User
superuser.com › questions › 1513976 › stop-infinite-loop-using-gui-in-bash
linux - Stop infinite loop using GUI in bash - Super User
gui(){ xmessage "Click to stop loop" -buttons Stop:7 touch "$filename" } ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... 1 using 'case $1 in' to read command options- multiple flags after dash, and handling unusual flags? 1 How to run an infinite loop program on startup on a Raspberry Pi without halting boot up