This code check if the last 4 characters of the variable $1 correspond to the string in variable $2 anticipated by a dot.
if [ "${1: -4}" == ".$2" ]; then
return 0
else
return 1
fi
// true with $1 = example.doc and $2 = doc
// false with $1 = example.docx and $2 = doc
how can I replace the hardcoded 4 with the following variable $CHECKER_EXTENSION calculated like this?
LENGTH_EXTENSION=${#2}
CHECKER_EXTENSION=$(( LENGTH_EXTENSION + 1 ))
Thanks in advance
Aucun commentaire:
Enregistrer un commentaire