really simple for loop question

apologies for the basicness of this question, but within a for loop how can i "list" my values as opposed to adding them to the same line

for example if i use this it works fine

for n in peter paul david
do
  echo "my name is $n"
done

but i wanted to list my items ( i have quite a few and dont want to go to an external file if possible)

This does not work

for n in 
peter 
paul 
david
do
  echo "my name is $n"
done

again sorry for this question, im sure its a really basic solution, but im missing it

I tried putting a backslash after each value but that didnt work

any help would be great

for n in \
peter \
paul \
david 
do
  echo "my name is $n"
done

try this.
When you have lots of item in a for loop it becomes hard to maintain the code.
You should extract the list to a file:
peter
paul
david
etc.
then do something to put all of those names onto the "command line" for the for loop:
one way to do that:

 for nm in $( awk '{printf( "%s ")}' file )
 do
   echo "my name is $nm"
 done

thanks for that :slight_smile: