for i in Alpha Beta Charlie; do
echo "$i"
done
You don't need eval
and you don't need ls
.
Alternatively, you could just print each of these directly, with a newline character after each:
printf '%s\n' Alpha Beta Charlie
Please don't use eval
unless you absolutely must. (Hint: Unless you get seriously complicated, you never need it.) Using eval
when you don't have to just leads to security holes.
Your initial question is very clear:
Write a loop to go through three values (A B C) and displays each of these values to the screen (hint use a ‘for’ loop).
However from your comment perhaps you want to execute some commands in a loop:
I want the value T exp 1 exp2 exp3 to execute
If you want to execute commands in a loop, just write the commands and put them in a loop:
for i in {1..3}; do
echo Hip Hip
echo 'HOORAY!'
done
The first line of this could just as easily be for i in A B C; do
and it would do the same thing. You don't use the variable $i
anywhere in your loop, but you don't have to. It will still execute three times.
echo
command doesn't change that. "...go through three values...display each of these values to the screen..." – Wildcard Apr 08 '16 at 04:20