'How do I repeat a command until successful? Not working as intended

I'm trying to implement a retry loop in Bash and it's not working the way I intended. I'm trying to repeat a command until it's successful.

When the command successfully completes, it contains the string/text "100.00%|" followed by a long text-based progress bar in the Terminal/console. In this case, I only care about the "100.00%" portion, and not the other stuff that comes after it (no space).

In other words, only the first seven characters of the "longer string". The command has been tested and works on single-iteration runs. Here's a snippet of how I'm implementing the code.

while ! "100.00%"
do
    Run command
    sleep 2
done

But couple things happen when I run the script. While it successfully continues to repeat itself on failed attempts, I keep getting the following error message.

./Script.sh: line 27: 100.00%: command not found

On top of that, looks like it continues to repeat itself even after successfully running the command and the string-snippet "100.00%" appears in the Terminal, which indicates something could be wrong with my syntax or logic. Is it not detecting the correct string? Am I missing something else in my loop? Could something be wrong with my syntax?

If "100.00%" appears in the console, by the logic, shouldn't it exit the loop and continue the script? How do I solve these issues?



Solution 1:[1]

You can try this

Run command
while [[ $? -ne 0 ]]
do
    Run command
    sleep 2
done

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 T.R