Use $(..) instead of legacy `..`.
Use grep -q instead of comparing output with [ -n .. ].
Quote the rhs of != in [[ ]] to prevent glob matching.
Use semicolon or linefeed before 'do' (or quote to make it literal).
Use 'cd ... || exit' or 'cd ... || return' in case cd fails.
Argument mixes string and array. Use * or separate argument.