how do I list my values one per line instead of across it?

I want to list my vars in a script so they look like

while read IN
var1
var2
var3
var4
do
echo $IN
done

Then in the same script have them read and processed.

the closest I can get is as follows but this is obviously wrong.
NOTE I want a list not all the entries on one line, that would be too easy.

while read IN; hello; you; other; test; ok; do echo $IN; done

Perhaps I should use a EOF tag?

hope this makes sense. :confused:

Thanks

---------- Post updated at 04:42 PM ---------- Previous update was at 04:19 PM ----------

By George I did it on my own.

LIST=`cat << EOF
ls
echo
udevinfo
fdisk
xdisk
dmidecode
lsusb
EOF`
echo $LIST
read
for i in $LIST
do
if which $i &> /dev/null
then
echo "There it is $i"
else
echo "$i It's not there"
fi

done

I think this is the right way any other suggestions are welcome though, I'd like to make it look cleaner.

i suggest put all the commands to a parameter file and read through it instead of writing it in a script. if in case you need to add more you can do so in the parameter file instead.

A couple of variations...

(cat <<EOF
var1
var2
var3
var4
EOF
) | awk '{print $0}'

or if you had your list in a file like suggested above...

awk '{print $0}' yourfile

Why use cat?

What's wrong with:

LIST="ls
echo
udevinfo
fdisk
xdisk
dmidecode
lsusb
"

?

Don't use which. It is non-standard, and it often doesn't work. Use type instead:

type $LIST

Thanks for your suggestions, I always find it interesting to see other peoples variations. (there are many ways to skin a cat as they say.)

I tried to use the type command but unfortunately it was not installed on all the servers the script was to run on, so I used a simple if test to see if the executable file existed instead.

:slight_smile:

type doesn't have to be installed; it is part of every Bourne-type shell of the last 20, if not 30, years.

If you don't have it, you must be using csh or tcsh. Those are non-standard shells that are not recommended for scripting.