If your command returns immediately, then just take your command and write the output to a variable.
output=$(xev | grep -A2 --line-buffered -E 'ButtonRelease' | grep -o 'button 1')
Then test if the output is empty with
[ -z "$output" ]
You can stick that in a while loop:
output=""
while [ -z "$output" ] ; do
sleep 5
output=$(xev | grep -A2 -E 'ButtonRelease' | grep --line-buffered -o 'button 1')
done
If your command is a blocking process, and you want to execute something based on its output, then you'll need to fork, and monitor that output.
# Make a temporary file
output=$(mktemp)
# Run your command
# > "$output" will send the output of that command to a file.
# The & at the end is a "fork". It means we will continue the script # while that command is running. You also need the --line-buffered
# option for all grep calls used
xev | grep -A2 --line-buffered -E 'ButtonRelease' | grep --line-buffered -o 'button 1' > "$output" &
# Save a handle to the forked process
pid=$?
# Start a loop, as long as the file/output doesn't exist or has a zero-size,
# stay in the loop
while [ ! -s "$output" ] ; do
echo "seperate command"
sleep 5
done
echo "We got something"
cat "$output"
# If you need to kill the original process, now's a good time
kill $pid
# Don't forget to delete the file
# 'trap' works well for doing this reliably.
rm "$output"