0

This is my sample bash code:

exec_command(){

    command_1="<some string 1>"
    command_2="<some string 2>"
    command_3="<some string 3>"
    now=$@
    echo $now   
}

    for (( i=1; i<=3; i++ )); do
      exec_command "command_$i"

Here the special variable $@ refers to another variable inside the function. I want echo $now to print the contents of command_1, command_2 and so on. Instead it just prints the output as command_1, command_2.

I tried using eval but I'm not sure how to set the substitution for the $i part. I could use an if else block to match each variable inside the function but it will be too clumsy. Is there any better way?

Muradin
  • 3
  • 4

0 Answers0