I'm trying to start a process (target_executable
) and have it run in the background. I know I could do that via ./target_executable &
but in the bash script that's running the show, I want to read the output of the process looking for a particular output. Then once the output is . found, I want to let the the script complete whilst the target process is left running in the background.
This is what I have so far but there are a number of things wrong (its not running the process in the background, and it never hits "Finished Reading" even though the ID is found):
echo "Starting Process..."
TARGET_ID=""
./target_executable | while read -r line || [[ "$TARGET_ID" == "" ]] ; do
TARGET_ID=$(echo "$line" | grep -oE 'Id = [0-9A-Z]+' | grep -oE '[0-9A-Z]{10,}')
if [ "$TARGET_ID" != "" ]
then
echo "Processing $line '$TARGET_ID'"
fi
done
echo "Finished Reading..."
Any thoughts?