Skip to content

Instantly share code, notes, and snippets.

@jimdiroffii
Created October 23, 2023 00:35
Show Gist options
  • Save jimdiroffii/e06bcc5dc9fcfffb02e5da2538ed35f5 to your computer and use it in GitHub Desktop.
Save jimdiroffii/e06bcc5dc9fcfffb02e5da2538ed35f5 to your computer and use it in GitHub Desktop.
Run a program until some output string is found
#!/bin/bash
counter=0
while true; do
counter=$((counter + 1))
output=$(./MyApp) # Execute the program and store its output
last_line=$(echo "$output" | tail -n 1) # Extract the last line of the output
echo "$output" # Print the output
if [ "$last_line" == "output" ]; then # Change this string to desired match
echo "Output found after: $counter" # Shows number of program executions
break # Exit the loop if the last line is "output"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment