* I previously asked a question but it was not the correct question. Now I made the correct question and fixed sample code. And I will up an answer which partially cites an answer to the previous question. *
I would like to default value to arrays in bash. Please see following,
function chmod_chown_func() {
local file_path="$1"
local chmod_options[2]=${2:='-R 744'} # This line has error.
local chown_options[2]=${3:='-R root:root'} # This line has error.
sudo chmod "${chmod_options[@]}" "${file_path}"
sudo chown "${chown_options[@]}" "${file_path}"
}
chmod_chown_func "test.txt"
The error message is
$2: cannot assign in this way
Thank you very much.