The bash script snippet
folder="some folder's name"
a="$folder/"*".pdf"
if [ "$a" != "$folder"'/*.pdf' ]
then
echo check
fi
never prints check
.
I'd expect it to print check
iff there is at least 1 file whose name ends in .pdf
in folder $folder
.
echo $a
and echo "$folder"'/*.pdf'
print exactly what I'd expect them to print: The former prints the matched paths iff there is at least 1 *.pdf
file in the specified folder and otherwise prints what the latter prints. The latter always prints the name of the specified older concatenated with /*.pdf
.
- Why does bash behave like that?
- How do I make it work?
[ "$#" -gt 0 ]
) always passes. It think this is because bash just doesn't replace the asterisk if there is no match, so there always is at least 1 result. – UTF-8 Oct 23 '17 at 22:41shopt -s nullglob
before that condition. – don_crissti Oct 23 '17 at 22:43