Array in shell script

Hi,

check=("/usr/local/bin/chk_nag | awk -F":" '{print $1}'" "/usr/local/bin/chk_kas | awk -F":" '{print $1}'" "/usr/local/bin/chk_was | awk -F":" '{print $1}'"
)

for i in "${check[@]}";
do
echo $i;
done

when I run this. It says Syntax error: "(" unexpected

Please advise.

check=("$(/usr/local/bin/chk_nag | awk -F: '{print $1}')" "$(/usr/local/bin/chk_kas | awk -F: '{print $1}')" "$(/usr/local/bin/chk_was | awk -F: '{print $1}')")
 for ((i=0;i<${#check[@]};i++))
do 
       echo ${check[$i]}
done

Thanks it works on Centos but not on Ubuntu.

Anyways will use it on centos.

Make sure you're using the BASH shell on both, not just some generic /bin/sh.

Arrays like this also work with ksh versions newer than 1988.