1

I need to include variable inside curl

for fname in "assets/*.drx"; do
    echo $fname
    curl -F file=@"$fname" "http://someurl.com/"    
    echo $fnamename
done

Result:

assets/5baa5caa414f1d7786e86d03_1545903119.11.drx
curl: (26) couldn't open file "assets/*.drx"
assets/5baa5caa414f1d7786e86d03_1545903119.11.drx

It seems curl uses glob expression, but echo uses actual filename. Why does curl behave like this? Why does echo see the actual variable and how can I use the filename inside curl?

1 Answer 1

5

You've quoted the * wildcard, preventing the shell from expanding it.

for fname in assets/*.drx; do
    printf '%s\n' "$fname"
    curl -F file=@"$fname" "http://someurl.com/"    
done

The fname variable was assigned the literal text assets/*.drx. When you used it unquoted in the echo, the shell dutifully expanded it.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.