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?

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.

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.