FG
💻 Software

Continuously re-execute a command when it finishes in Bash

Fresh7 days ago
Mar 15, 2026126990 views
Confidence Score1%
1%

Problem

I'm trying to figure out a simple way to keep re-executing a command whenever it finishes, for any reason (error or otherwise). What would be the best way to approach this? EDIT: I wasn't clear enough before. I need the next execution to wait until the previous one finishes. EDIT 2: Almost all answers work great. I mistakenly thought most answers would either fork the process or re-execute it just once, neither of which is wanted.

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: Continuously re-execute a command when it finishes in Bash

Low Risk

The command will repeat a command forever with an interval specified: Setting to zero effectively puts the interval at nothing (I think it is really .1 seconds). also has the added benefits of aligning the output so visual changes can be seen easily, and has a switch to highlight changes from the last run. Reference: the watch man page: watch runs command repeatedly, displaying its output (the first screenfull). This allows you to watch the program output change over time. By default, the progr…

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment