My googlefu is failing me. I have a bunch of variables I read it from a CSV where I want to strip whitespace. I could
variable1="$(echo -e "${variable1}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
variable2="$(echo -e "${variable2}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
variable3="$(echo -e "${variable3}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
but then I'm copying in and editing this for every variable change. It seems to me, from other languages, there should be a way to do a simple for loop that applies to the variables as named and strips the whitespace, but I can't figure out exactly how to do that.
for $i in variable1 variable2 variable3
do
$i=$(echo -e "${$i}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
done
but this doesn't work as far as I can tell. What I want to do is loop over all the variables, strip whitespace, but not have to manually type out each variable name in the script.