Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

up vote 5 down vote accepted

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
share|improve this answer
    
Or even echo "$hello and $goodbye".* (mix variable expansions, spaces, and a glob in the same "word". –  vonbrand Mar 13 '13 at 13:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.