Bash code to check if file begins with a string
FILE=/etc/passwd if [[ $FILE == /etc/* ]]; then echo "match" fi
match
Env: GNU bash, version 4.2.46
Note the presence of double square brackets ([[ ]])
Bash code to check if file begins and ends with something
FILE=/etc/passwd if [[ $FILE == /e*/passwd ]]; then echo "match" fi
match
Env: GNU bash, version 4.2.46
Bash code for file name matching if filename has space
FILE="/etc/pass d" if [[ $FILE == /*"/pass d" ]]; then echo "match" fi
match
Env: GNU bash, version 4.2.46