Search code examples
bashloopswine

Append multiple arguments and use them in a single command


So what I'm intending to do here is to create a part of a script that can open a single or multiple torrents with µtorrent (through wine).

The Wine path needs to be appended to the arguments like so (the loop is obviously not working):

for i in "$@"; do
  open="Z:/$(pwd)/$i"
done

wine utorrent "$open"

Solution

  • I would use an array:

    args=()
    pwd=$(pwd)
    for i; do
        args+=("z:/$pwd/$i")
    done
    wine utorrent "${args[@]}"
    

    In a bash for loop, if you leave out the in ... clause, it iterates over "$@" by default.