0

Why does the following only output 'b' and not 'b c'? What's the best way to make it output 'b c' please?

#!/usr/local/bin/bash
# The above is GNU bash, version 5.2.2(1)-release (x86_64-apple-darwin21.6.0)
# installed using Homebrew on macos Monterey

test() {
    shift
    xx=("$@")
}
test a b c
echo $xx

PS: Apologies if this is a duplicate - I searched but there were 14,501 results. :-(

BruceH
  • 494
  • 6
  • 11
  • 5
    `xx` is an array, and the expansion `$xx` expands to the first argument (here `a`). Use the array expansion: `echo "${xx[@]}"`. – gniourf_gniourf Oct 17 '22 at 20:03
  • D'oh! Thank-you. I'd convinced myself it was the assignment that was going wrong, not the printing out later. – BruceH Oct 17 '22 at 21:33

0 Answers0