bash: wait for specific command output before continuing <p>I know there are several posts asking similar things, but none address the problem I'm having.</p> <p>I'm working on a script that handles connections to different <code>Bluetooth low energy</code> devices, reads from some of their handles using <code>gatttool</code> and dynamically creates a <code>.json</code> file with those values.</p> <p>The problem I'm having is that <code>gatttool</code> commands take a while to execute (and are not always successful in connecting to the devices due to <code>device is busy</code> or similar messages). These "errors" translate not only in wrong data to fill the <code>.json</code> file but they also allow lines of the script to continue writing to the file (e.g. adding extra <code>}</code> or similar). An example of the commands I'm using would be the following:</p> <pre><code>sudo gatttool -l high -b &lt;MAC_ADDRESS&gt; --char-read -a &lt;#handle&gt; </code></pre> <p>How can I approach this in a way that I can wait for a certain output? In this case, the ideal output when you <code>--char-read</code> using <code>gatttool</code> would be:</p> <pre><code>Characteristic value/description: some_hexadecimal_data` </code></pre> <p>This way I can make sure I am following the script line by line instead of having these "jumps".</p>