bash bug - 07/19/17 02:57 PM
a bash bug that made me pull out some hair, for anyone that cares
you expect:
and you get:
it seems when you use ${variable[@]} inside a string, and pass it to a function, it tries to split out the array elements into the different function parameters, even though it's all in quotes.
Code:
#!/bin/bash x[0]="zero" x[1]="one" x[2]="two" print () { echo "param 1: \"$1\"" echo "param 2: \"$2\"" echo "param 3: \"$3\"" } echo "first form:" print "test 1: ${x[@]}" echo "second form:" y="${x[@]}" print "test 2: $y"
you expect:
Code:
first form: param 1: "test 1: zero one two" param 2: "" param 3: "" second form: param 1: "test 2: zero one two" param 2: "" param 3: ""
and you get:
Code:
first form: param 1: "test 1: zero" param 2: "one" param 3: "two" second form: param 1: "test 2: zero one two" param 2: "" param 3: ""
it seems when you use ${variable[@]} inside a string, and pass it to a function, it tries to split out the array elements into the different function parameters, even though it's all in quotes.