I've got a directory with various files:


And I want to loop through all the .jsx files. So I wrote this Bash script:

for JSX_FILE in "$BUILD_DIR/*.jsx"; do   
    echo $JSX_FILE
    echo "PATH: $JSX_FILE"
    JSX_FILENAME=$(basename "$JSX_FILE")
    echo "NAME: $JSX_FILENAME"

But for some reason that would print this:


PATH: /path/to/*.jsx

NAME: *.jsx

So I don't understand why in one case $JSX_FILE has the value /path/to/View.jsx and in another case it has the value /path/to/*.jsx. How can I make sure this variable will have the same value everywhere within the loop?

  • 1
    what do you think is the difference between echo $JSX_FILE and echo "$JSX_FILE" ? – Jimmy Nov 4 '17 at 17:43

Quoting the glob inhibits globbing.

for JSX_FILE in "$BUILD_DIR"/*.jsx; do   
| improve this answer | |
  • 4
    Specifically, the asterisk gets passed in to the loop unchanged, and then it's only expanded when the shell runs the echo command. – dannysauer Nov 4 '17 at 22:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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