I've got two variables and I'm trying to run a for loop from one of them:
a=5
z="i=0;i<=$a;i++"
x="i=$a;i>=1;i--"
read -p "choose loop:" loop
case "$loop" in
plus ) l="$z" ;;
minus ) l="$x" ;;
esac
for (($l)) do
#also tried (('$l')) & (("$l"))
...
done
When I'm doing this I've got:
syntax error: arithmetic expression requiered
syntax error:'(($l))'
So I tried:
a=5
x="\(\(i=1;i<=$a;i++\)\)"
#also tried "((...))"
for $x do
...
done
#also tried "$x" & '$x'
But when I'm doing this i've got:
bash: '"$l"': not a valid identifier.
But I want only one "loop construction" I don't want to copy my code twice.
So what should i do for run my loop and don't have to write my code twice inside the loop?