Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-1· AnthropicHugging Face Arena Human Preference 55K

In ZSH, what's the idiomatic way to run a program repeatedly until it fails?

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Claudeclaude-2.1’s answer.
  1. User

    In ZSH, what's the idiomatic way to run a program repeatedly until it fails?

  2. Claude Assistant

    In ZSH, you can use a while loop to repeatedly run a program until it fails:

    while true; do
        program_name
        if [[ $? -ne 0 ]]; then
            break
        fi
    done
    

    This will:

    • Run an infinite while loop with while true
    • Run the program_name program
    • Check if the exit status $? is not 0, indicating the program failed
    • If so, break out of the loop with break
    • Otherwise, continue looping and running the program

    So this will repeatedly run the program until it eventually fails, at which point the loop exits.

    For example, to repeatedly ping a host until it fails:

    while true; do
        ping -c 1 example.com
        if [[ $? -ne 0 ]]; then
            break
        fi
    done
    

    This is a very idiomatic way to write a retry loop in ZSH. Let me know if you have any other questions!

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.