I am trying to redirect the output of a command that contains couple of user input variables to an array. I first tried this script -
echo "Type the ACL name"
read acl
echo "Type the DATACENTER name"
read dc
echo "ACL is $acl, DC is $dc"
mkdir ~/$acl
device=($(grep -iEr $acl ~/sync-configs/$dc/configs/* | awk -F ':' {'print $1'} | awk -F '/' {'print $NF'} | sort | uniq))
The script created the ~/acl directory just fine but the grep did not work for me. Then, after doing some research, I adjusted the grep to put the variables in double quotes, like this -
echo "Type the ACL name"
read acl
echo "Type the DATACENTER name"
read dc
echo "ACL is $acl, DC is $dc"
mkdir ~/$acl
device=($(grep -iEr "$acl" ~/sync-configs/"$dc"/configs/* | awk -F ':' {'print $1'} | awk -F '/' {'print $NF'} | sort | uniq))
This seems to work fine and I am able to see elements in the device array.
My question is why do I need to put the $acl and $dc quotes when feeding them to the array but the command mkdir ~/$acl
doesn't require any quotes? Can some one provide clarity on this?
acl
anddc
, wouldn't it.