Could some one help to find out what is problem with my for loop script. I'm trying to install packages from a list of variables using a for loop.My issues is when go grab the first package to be installed it and goes grab package from the list at the same time. Also it will install the packages all at the same time. How do I check fix it. I need to do one at a time.REQPKGS=redhat-lsb-core telnetfor pkg in $REQPKGS; do    if yum -q list installed $REQPKGS > /dev/null 2>&1; then        echo -e $pkg is already installed    else        yum install $REQPKGS -y        echo Successfully installed $REQPKGS    fidoneResult of my script:+ REQPKGS='redhat-lsb-core telnet'+ for pkg in '$REQPKGS'+ yum -q list installed 'redhat-lsb-core telnet'+ yum install redhat-lsb-core telnet -y+ echo 'Successfully installed redhat-lsb-core telnet'Successfully installed redhat-lsb-core telnet+ for pkg in '$REQPKGS'+ yum -q list installed 'redhat-lsb-core telnet'+ yum install redhat-lsb-core telnet -yLoaded plugins: product-id, refresh-packagekit, rhnplugin, security, subscription-managerThis system is receiving updates from RHN Classic or RHN Satellite.Setting up Install ProcessPackage redhat-lsb-core-4.0-7.el6.x86_64 already installed and latest versionPackage 1:telnet-0.17-48.el6.x86_64 already installed and latest versionNothing to do+ echo 'Successfully installed redhat-lsb-core telnet'Successfully installed redhat-lsb-core telnet
packages to be install in a for loop if not installed
shell script;software installation;yum
You use your array variable ($REQPKGS) inside your loop instead of the loop variable ($pkg), so it's doing exactly what you told it to do, install both packages at the same time twice.Change the inside of your for loop to:REQPKGS=(redhat-lsb-core telnet)for pkg in ${REQPKGS[@]}; do    if yum -q list installed $pkg > /dev/null 2>&1; then        echo -e $pkg is already installed    else        yum install $pkg -y && echo Successfully installed $pkg    fidoneWhen using a for loop, the variable you define after for holds the value for each iteration of the loop; in your case the variable that contains a single package at a time is $pkg.AlternativelyREQPKGS=(redhat-lsb-core telnet)yum install -y ${REQPKGS[@]}Will install any packages specified that aren't installed, and skip any packages that are already installed.