Wildcards inside quotes

27,101

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:
27,101

Related videos on Youtube

Gilles 'SO- stop being evil'
Author by

Gilles 'SO- stop being evil'

Updated on September 18, 2022

Comments

  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' almost 2 years

    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?

  • vonbrand
    vonbrand over 11 years
    Or even echo "$hello and $goodbye".* (mix variable expansions, spaces, and a glob in the same "word".
  • CMCDragonkai
    CMCDragonkai over 8 years
    Globbing doesn't seem to work in this case, echo /path/to/file/*${variable}. How do I glob while appending an interpolated email?
  • LostBalloon
    LostBalloon over 8 years
    @CMCDragonkai echo "$FOLDER_PATH"/*.extension works fine for me, contrary to the accepted answer, I had to remove the whitespace between the " and the *. Hope it helps.
  • agrosner
    agrosner over 5 years
    @CMCDragonkai, @LostBalloon I use the following pattern when I want to use globs with variables that may have spaces: (cd "$FOLDER_PATH" && echo *.extension)