I have a bash script which makes some system changes involving a list of URL addresses beginning with http, and I'm trying to write a GUI for it.I'm stuck with the following last part:changes=$(cat /home/$USER/.updates.log | grep http)if [ $changes != 0 ]; then    zenity --question --text Changes found in:\n$changes\n\nWould you like to update now?        if [ $? = 0 ]        then# passwordsudo_password=$(gksudo --print-pass --description 'MyScript' -- : 2>/dev/null)# check for null entry or cancellationif [[ ${?} != 0 || -z ${sudo_password} ]]then    exit 4fiif ! sudo -kSp '' [ 1 ] <<<${sudo_password} 2>/dev/nullthen    exit 4fi# notifynotify-send Applying updates... -i gtk-dialog-info -t 1000 -u normal &# proceed to updatecuser=${SUDO_USER:-$USER}sudo -Sp ''  sudo /usr/local/bin/MyScript <<<${sudo_password}# option to view lognew_update=$(cat /home/$USER/.updates.log | grep 'MyScript completed at ' | awk -F ' at ' '{print $2}')zenity --question --text MyScript updated at $new_update\n\nWould you like to view the log file now?if [ $? = 0 ]then# display log    zenity --text-info --filename=/home/$USER/.updates.log --width 680 --height 680fififiActually, it seems the tricky part for me is here: if [ $changes != 0 ]; thenI want to simply display a message like No updates found; exiting... if that file contains no lines beginning with http but this simply creates a blank line in the zenity question dialog box. It seems I need to modify this line, and also add another command under else but I just don't know how and where...
Newbie trying to write a simple GUI for a simple bash script
bash;shell script
I can't test the rest of your script since I don't have the necessary data and don't even know what it does but this line is certainly wrong:changes=$(cat /home/$USER/.updates.log | grep http)That will save the output of your grep command in $changes, not the number of times the string was found, but the actual lines returned. For example:$ cat file one httptwo httpthree http$ changes=$(cat file | grep http)$ echo $changes one http two http three httpAs you can see above, $changes is just each matching line from the file concatenated into a single variable. What you wanted was something like (no need for cat, by the way, grep can take a filename as input):$ changes=$(grep -c http file)$ echo $changes 3The -c switch makes grep print the number of matching lines instead of the lines themselves. Alternatively, you can pass the output through wc -l to count the lines:changes=$(grep http file | wc -l)Either one will do and you will now be able to check whether $changes is greater than 0:if [ $changes -gt 0 ]]; then         ...fiIf you want to display the changes, use your original approach but don't compare it to 0. Instead, use -z to check whether the variable is empty:changes=$(grep http /home/$USER/.updates.log)## If $changes is emptyif [ -z $changes ]then     notify-send Found no updates; exiting... -i gtk-dialog-info -t 1000 -u normal &     exitelse     zenity --question --text Changes found in:\n$changes\n\nWould you like to update now?    ...fi