This is the code I am dealing with:
function execute {
task="$1"
servername="$2"
"$task" "${servername[@]}"
}
function someOtherThing {
val=$1
echo "$val"
}
function makeNecessaryDirectory {
arr=("$@")
echo "${arr[@]}"
}
dem=(1 2 3 4 5)
execute someOtherThing 1
execute makeNecessaryDirectory "${dem[@]}"
Output:
1
1
Expected output:
1
1 2 3 4 5
How to achieve this? I found no error logically.
Side question:
Is it safe to always receive 2nd parameter as an array inside execute so that it can deal with both of the dependent functions, or i should have an explicit check inside execute?
makeNecessaryDirectory, so$@is just 1.1,1,2,3,4,5(all on separate lines)?makenecessaryDirectory.execute() { "$@"; }? it seems that's what you're after…