Return value from array inside a function based on parameter

Viewed 407

gurus. I'm developing a bash script and learning about arrays in bash. I read a couple of howto about that but my head blew up. I used to program in php and bash is new and "rudimentary" for me.

I'm going to put multilang support to my script and I need to define all visible phrases in different arrays to get them calling a function with a parameter. Hard to explain I'll put what I want to do in php what is my "comfort" language and then my not working aproximation in bash script.

Php:
function english($index) {
    $strings=array(
                "phrase1",
                "phrase2"
                );
    return $strings[$index];
}
echo english(1); //It produces (zero based) "phrase2"

Ok, now my poor bash script trying to do the same:

Bash:
function english() {
    strings=("phrase1" "phrase2")
    return ${strings[$1]}
}
echo english 2

How can I return the desired value of array calling a function containing the array and based on the function parameter?

Anyone has a good bash manual to do some practices about this? Thank you.

2 Answers
Related