I am wondering if there is a better way in bash when passing an array of values to a program like zip since shell check complains like shown in the example. First call shows a way which works but shell check complains, second zip does not work but shell check is happy.
After this question was closed since I guess oversimplified the example an tried a few thing using the lings supplied and came up with this solution. I added brackets around the call of find and added declare -a. Now both zip calls work.
Is that the correct way of solving this problem?
What is the preferred way to solve this in bash?
#!/bin/bash
touch file1.txt
touch file2.txt
declare -a filenames=($(find . -name "file*.txt"))
zip_filename="myzip.zip"
#works but shell check complians https://github.com/koalaman/shellcheck/wiki/SC2068
zip -v -j "works_${zip_filename}" ${filenames[@]}
#does not work
zip -v -j "not_working_${zip_filename}" "${filenames[@]}"