vendredi 20 octobre 2017

print 'something' if all conditions in an if-else statement are empty

I have a function in a bash script that does a diff on files. I have set to echo the diff if one exists, however if none exist I would like to only print out "No differences found in ANY Task Definitions"

Here is what I have;

diff_taskDef () {
MAS=master.json
CUR=current.json
clear
mapfile -t awsReg < <(ls ~/regions)
for awsrg in "${awsReg[@]}"; do
 mapfile -t awsTD < <(ls ~/regions/"$awsrg")
    for td in "${awsTD[@]}"; do
     DIFF="$(diff -q ~/regions/"$awsrg"/"$td"/"$td"-"$MAS" ~/regions/"$awsrg"/"$td"/"$td"-"$CUR")"
       echo "$DIFF"
    done
done

So rather than a blank screen, or scrolling through EVERY statement without a positive diff saying "no diff found" I just want one if nothing is different

Aucun commentaire:

Enregistrer un commentaire