the functions
GNU bash version 3.1.17 (non-upgradeable)
Premise
I worked with arrays, and I was wondering if there is a way to have a local variable for a function with the same name as the array outside the specified function.
Example
In the examples below, I will try to display the problem
IN
#!/bin/bash arr=(1 2 "3 4" 5) # Make global array myfunc() { local args=("${!1}") # Using different name for declaration echo ${args[@]} # Echo new array } myfunc arr[@] # Pass array to function
Exit
1 2 3 4 5
Does not work
#!/bin/bash arr=(1 2 "3 4" 5) # Create array myfunc() { local arr=("${!1}") #Not working echo ${arr[@]} # Not working } myfunc arr[@] # Pass array to function
Exit
[Blank]
Cause
I want to pass multiple arrays to a function, but I donβt want to have a possible collision of names with the passed array and the name of the local array.
I tried
As you can see above, I tried to add a local function. I looked through the bash man page and cannot find anything that could provide the behavior I desisre
Bash -x Results
+ arr=(1 2 "3 4" 5) + myfunc 'arr[@]' + arr=("${!1}") + local arr + echo
If you need more information, please let me know.
source share