So I have a function I'd like to unpack an array of params to form the argument sequence:
#!/usr/bin/env bash
my_func() {
echo "IN LEN: $#" # Gives "6" -> Should be "4"
echo "IN: $@" # Gives "--a 1 --b 2 3 4" -> Should be "--a 1 --b 2\n3\n4"
}
read -r -d '' MULTI << EOM
2
3
4
EOM
ARGS=("--a" "1" "--b" "$MULTI")
echo "OUT LEN: ${#ARGS[@]}" # 4
echo "OUT: ${ARGS[@]}" # "--a 1 --b 2\n3\n4"
my_func ${ARGS[@]}
This example demonstrates the issue and what I'm expecting. Maybe some magic with setting IFS
? Any suggestions?
PS. See my original question if you need some more context: Handle optional function arguments