Wildcards in Quotes – How to Use Wildcards Inside Quotes

quotingshellwildcards

This will be an easy one, but in my memories, when shell scripting, using double quotes would allow expanding globbing and variables.

But in the following code:

#!/bin/sh

echo *.sh
echo "*.sh"
echo '*.sh'

echo $LANG
echo "$LANG"
echo '$LANG'

I get this result:

bob.sh redeployJboss.sh
*.sh
*.sh
en_US.utf8
en_US.utf8
$LANG

So single quoting prevent glob AND variable expansion but double quoting allows only variable expansion and no globbing?

Can I glob in any quoting pattern?

Best Answer

You are correct: globbing doesn't work in either single- or double-quotes. However, you can interpolate globbing with double-quoted strings:

$ echo "hello world" *.sh "goodbye world"
hello world [list of files] goodbye world