1

I have two functions that only store variables. Example:

Function datanode1(){
    homedirectory = "/path/to/file"
    ConfigDirectory = "/path/to/file"
    user = "john"
    max_open_Files = 262114
}

datanode2 is exactly the same, just different path files.

I would like to do something like this:

if [ "$a1" == "all" ]; then
    for i in [datanode2, datanode1] do
        *execute Script*
    done
fi

Is this possible? How are the functions acting as arrays?

2
  • Not Function, but function. and not both function and (). Just use datanote1() { ...; } Commented Dec 13, 2018 at 22:25
  • And not var = value but var=value -- see Shell Parameters and Simple Command Expansion Commented Dec 13, 2018 at 22:28

1 Answer 1

2

If you have functions named datanode2 and datanode1, and you want to execute them in a loop, you could write like this:

for fun in datanode2 datanode1; do
    "$fun"
done

Btw the function definition in your example has some syntax error. It should be more like this:

datanode1() {
    homedirectory="/path/to/file"
    ConfigDirectory="/path/to/file"
    user="john"
    max_open_Files=262114
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.