Skip to main content
added 315 characters in body
Source Link
Rakib
  • 2.5k
  • 1
  • 22
  • 20

Just change your for loop :

for index in ${array_item[*]}
    do
       check_$index
    done

Full script

#!/bin/bash

array_item=(item1 item2)

#function
check_item1 ()
{
   echo "hello from item1"
}
check_item2 ()
{
   echo "Hello from item2"
}   

for index in ${array_item[*]}
    do
       check_$index
    done

NB: In addition the following funky constructs are available:

${array_item[*]}         # All of the items in the array
${!array_item[*]}        # All of the indexes in the array
${#array_item[*]}        # Number of items in the array
${#array_item[0]}        # Length of item zero

Just change your for loop :

for index in ${array_item[*]}
    do
       check_$index
    done

Full script

#!/bin/bash

array_item=(item1 item2)

#function
check_item1 ()
{
   echo "hello from item1"
}
check_item2 ()
{
   echo "Hello from item2"
}   

for index in ${array_item[*]}
    do
       check_$index
    done

Just change your for loop :

for index in ${array_item[*]}
    do
       check_$index
    done

Full script

#!/bin/bash

array_item=(item1 item2)

#function
check_item1 ()
{
   echo "hello from item1"
}
check_item2 ()
{
   echo "Hello from item2"
}   

for index in ${array_item[*]}
    do
       check_$index
    done

NB: In addition the following funky constructs are available:

${array_item[*]}         # All of the items in the array
${!array_item[*]}        # All of the indexes in the array
${#array_item[*]}        # Number of items in the array
${#array_item[0]}        # Length of item zero
Source Link
Rakib
  • 2.5k
  • 1
  • 22
  • 20

Just change your for loop :

for index in ${array_item[*]}
    do
       check_$index
    done

Full script

#!/bin/bash

array_item=(item1 item2)

#function
check_item1 ()
{
   echo "hello from item1"
}
check_item2 ()
{
   echo "Hello from item2"
}   

for index in ${array_item[*]}
    do
       check_$index
    done