My bash script:

MY_ARRAY=("Some string" "Another string")
function join { local IFS="$1"; shift; echo -e "$*"; }
join "," ${MY_ARRAY[@]}

I want the output to be: Some string,Another string.

Instead, I get Some,string,Another,string.

What must I change to get the result I want?


My modified version of your script:

my_array=("Some string" "Another string")
my_join() {
  [ "$#" -ge 1 ] || return 1
  local IFS="$1"
  printf '%s\n' "$*"
my_join , "${my_array[@]}"


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.