1

I am using a bash script to generate a list of files, where each file name might contain spaces (it is on Windows, with Git Bash, and I need something that works with Bash 3).

The script does roughly that:

_my_function() {
  for i; do 
    echo $i
  done
}

_test() {
  local do_add_list
  do_add_list[0]='Some file'
  do_add_list[1]='Another file'  
  _my_function $do_add_list[@]
}

While I don’t really want to pass the array as is, I’d like to pass it as arguments of _my_function like xargs or as something like,

_my_function 'Some file' 'Another file'

How can I do that in Bash 3 (msys port of bash3), apart from as a global variable?

TRiG
  • 9,249
  • 6
  • 50
  • 101
NoDataFound
  • 9,100
  • 27
  • 52

1 Answers1

6

Instead of

_my_function $do_add_list[@]

do

_my_function "${do_add_list[@]}"
user000001
  • 28,881
  • 12
  • 68
  • 93
  • 1
    It worked. I don't know how bash does it, but _my_function `a ${do_add_list[@]} b` also prepend to first array args, and append to last array args. I just hope it will not fails on Windows (I tested it on ubuntu). – NoDataFound Nov 29 '13 at 16:54