Saturday, 24 July 2021

Return a particular value if the given array value doesn't exist

 if [ "${backups[$service]:-NOT_HERE}" != "NOT_HERE" ]; then

    # do what you want if the value does exist in the array
fi


from: https://stackoverflow.com/questions/44823572/get-an-element-from-a-associative-array-in-bash-with-set-u

No comments:

Post a Comment

How to check if a file contains a specific string using Bash

 In case if you want to check whether file does not contain a specific string, you can do it as follows. if ! grep -q SomeString "$File...