0

I want to assign a value to the array I gave as a parameter as follows. But I am not getting the array correctly. I tried to send the array as a parameter with the following method.

Func()
{
  parameter=$1
  echo $parameter
  for ((i = 0; i < 26; i++)); do
    parameter[$i]=0
  done
}
Func "${array_kelime1[@]}"
Cyrus
  • 84,225
  • 14
  • 89
  • 153
  • 1
    `$1` is only the _first_ part of the array. The rest of it goes in `$2` and onward. Each array element becomes a separate argument. – Charles Duffy Oct 03 '22 at 20:32
  • what should i do @CharlesDuffy – Sultan Çepni Oct 03 '22 at 21:00
  • If your goal is to _modify_ the array, use a namevar (`declare -n parameter=$1`), and pass `Func array_kelime1`. Note that this requires a modern bash release (I don't remember if they were introduced in 4.1 or 4.3, but something in that range -- it's a feature not available in the 3.x release MacOS ships). – Charles Duffy Oct 03 '22 at 22:05

0 Answers0