I'm using this line in a bash script for executing a command with a defined number of options/ arguments
message=$(mp3wrap "$file_out.mp3" "$file_in_1" "file_in_2" 2>&1 && echo "Success")
How can I fiddle this line for a dynamic range of options from an array?
For example, I have to call "mp3wrap" with 2, 4 or 6 "file ins" from myarray. If I concatenate the filenames with spaces in an variable, it's interpretet as one option and fails.
Also it's important to have the filenames in double quotes for file names with spaces.
This is exactly what arrays were designed to do.
files=(file_in_1 file_in_2 file_in_3)
message=$(mp3wrap file_out.mp3 "${files[@]}" 2>&1 && echo "Success")