Conditionally execute command in Linux shell script
<p>I use Cordova CLI to create Android APKs on my Ubuntu 16.04 VPS server.  Once the APK has been built I copy it to Dropbox on local machine and then install the APK on my Android test devices.  I want to use the Dropbox API to upload the APK directly so I avoid the unnecessary 3 way transfer:</p>

<pre><code>Server -&gt; Local Machine -&gt; Dropbox -&gt; Android test device.
</code></pre>

<p>The sequence of operations would go like this</p>

<ul>
<li>Shell scripts (already written) on the server cleanup the Android source and rebuild the APK</li>
<li>This is done with Phonegap/Cordova verbose output on which ensures that a successful build emits the following text at the end</li>
</ul>

<p>BUILD SUCCESSFUL</p>

<pre><code> Total time: 5.495 secs
 Built the following apk(s): 
 /path/to/app/source/platforms/android/build/outputs/apk/android-debug.apk


No scripts found for hook "after_compile".


No scripts found for hook "after_build".


[36m[phonegap][39m completed 'cordova build android -d --no-telemetry'
</code></pre>

<p>The final step - uploading the android apk to my Dropbox should only be done if BUILD SUCCESSFUL is found in the Cordova/Phonegap debug output.  I have got everything in place but I am not sure how I should check for BUILD SUCCESSFUL</p>

<p>Here is the pseudocode in the shell script</p>

<pre><code>!# /bin/bash
pgclean;
# pgclean is another shell script that cleans up the Phonegap project in the 
# current folder
pgbuild;
# this rebuilds the APK and saves the detailed debug output to
# /path/to/my/project/debug.txt
# it is debug.txt which would contain BUILD SUCCESSFUL etc
</code></pre>

<p>Here is where my knowledge of bash scripts hits the buffers.  What I would like to do next:</p>

<ul>
<li>Test debug.txt, above, to ensure that the build is successful</li>
<li><p>If so call my final shell script</p>

<p>moveapktodropbox $1</p></li>
</ul>

<p>where $1 is the parameter I pass to the current shell script to provide the name under which the APK should be stored in Dropbox.</p>