Search code examples
bashvariablesbackticks

Bash insert a variable into a backticked command


I need to use this command

/usr/local/bin/mcl find -f .bz2

which returns me this

:???????? '/Cloud Drive/test1.bz2'
:???????? '/Cloud Drive/test2.bz2'

into a BASH script. The problem is that I need the last parameter (.bz2) to be a variable.

I've tried with this

FILENAME=".bz2"
UPLOADED=$(/usr/local/bin/mcl find -f $FILENAME)
# do something with $UPLOADED

But obviously it is not working. After some research on StackOverflow and on the web I have found several ways to do something like that (even using backticks), but still I can't manage to make it work.

What is the correct way to do that?


Solution

  • You mean like this?

    uploaded=$(mcl find -f "$FILENAME" | cut -d"'" -f2)
    for u in $uploaded; do
        echo "$u"
        # process "$u"
    done