Let's say I generate a two directories with text files in each like so
mkdir "Directory1" mkdir "Directory2" touch "Directory1/fileclass1_"{1..5}".txt" touch "Directory1/fileclass2_"{1..5}".txt" touch "Directory2/fileclass1_"{1..5}".txt" touch "Directory2/fileclass2_"{1..5}".txt" Suppose I verify all the files are inside by doing
A=( "Directory1" "Directory2" ) B=( "fileclass1" "fileclass2" ) for a in "${A[@]}"; do for b in "${B[@]}"; do for i in {1..5}; do name="${a}/${b}*${i}.txt" [[ ! -e $name ]] && echo "$name Does Not Exist" done done done This returns
Directory1/fileclass1*1.txt Does Not Exist Directory1/fileclass1*2.txt Does Not Exist ... However, if I instead replace the double brackets with singles, I get
A=( "Directory1" "Directory2" ) B=( "fileclass1" "fileclass2" ) for a in "${A[@]}"; do for b in "${B[@]}"; do for i in {1..5}; do name="${a}/${b}*${i}.txt" [ ! -e $name ] && echo "$name Does Not Exist" done done done which returns nothing, indicating all files are indeed there.
Why is it in this case, the double brackets fail, while single brackets work? I was under the assumption I should always employ double brackets, is the wildcard in string matching creating something I shouldn't have?
man bash: Word splitting and pathname expansion are not performed on the words between the[[and]]