BharathKumarRaju DasaraRaju
asked on
help me to understand linux shell script contains ${var[@]}
CWD=`pwd`
var=(SUUSERNAMECliqr SUPASSWORDCliqr ISSERVERENDPOINTCliqr APISERVERENDPOINTCliqr DOMAINCliqr EMAILCliqr ENDPOINTCliqr TETUSERNAMECliqr TETPASSWORDCliqr)
RSYNC=`which rsync`
# import environment
. $ENVFILE
# Copying JSON payload to local
$RSYNC -ar $CWD/deps/datadump/ $CWD/jsondata
# Setting up JSON DATA
for i in `ls $CWD/jsondata`
do
for j in ${var[@]}
do
sed -i -e "s,$j,${!j},g" $CWD/jsondata/$i 2>/dev/null ;
done
done
i have some jsonfiles like 1.json , 2.json ,3.json in the directory $CWD/jsondata/..
what i understands is the value SUUSERNAMECliqr substitutes as $SUUSERNAMECliqr to the files 1.json , 2.json ,3.json ... this i understood from the command sed -i -e "s,$j,${!j},g" $CWD/jsondata/$i 2>/dev/null ; ......
but my confusion is how this for loop ... for j in ${var[@]}......substitutes values from the array declared var=(SUUSERNAMECliqr SUPASSWORDCliqr ISSERVERENDPOINTCliqr APISERVERENDPOINTCliqr DOMAINCliqr EMAILCliqr ENDPOINTCliqr TETUSERNAMECliqr TETPASSWORDCliqr).......
i.e. how @ symbol tells to check all the values in array i.e. for j in ${var[@]} ..... can any one explain me this please ?
for j in ${var[@]}
do
sed -i -e "s,$j,${!j},g" $CWD/jsondata/$i 2>/dev/null ;
done
var=(SUUSERNAMECliqr SUPASSWORDCliqr ISSERVERENDPOINTCliqr APISERVERENDPOINTCliqr DOMAINCliqr EMAILCliqr ENDPOINTCliqr TETUSERNAMECliqr TETPASSWORDCliqr)
RSYNC=`which rsync`
# import environment
. $ENVFILE
# Copying JSON payload to local
$RSYNC -ar $CWD/deps/datadump/ $CWD/jsondata
# Setting up JSON DATA
for i in `ls $CWD/jsondata`
do
for j in ${var[@]}
do
sed -i -e "s,$j,${!j},g" $CWD/jsondata/$i 2>/dev/null ;
done
done
i have some jsonfiles like 1.json , 2.json ,3.json in the directory $CWD/jsondata/..
what i understands is the value SUUSERNAMECliqr substitutes as $SUUSERNAMECliqr to the files 1.json , 2.json ,3.json ... this i understood from the command sed -i -e "s,$j,${!j},g" $CWD/jsondata/$i 2>/dev/null ; ......
but my confusion is how this for loop ... for j in ${var[@]}......substitutes
i.e. how @ symbol tells to check all the values in array i.e. for j in ${var[@]} ..... can any one explain me this please ?
for j in ${var[@]}
do
sed -i -e "s,$j,${!j},g" $CWD/jsondata/$i 2>/dev/null ;
done
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER