while read VAR ; do
echo the read line is: $VAR # this is an example how to use the variable
done < /path/to/your/input.file
If your line has several words you can use the shells field-splitting abilities to read the line into several variables. The first "field" goes to the first variable, the second to the second variable, etc. If there are less input words than variables the last variables will be empty. If there are more input words the last variable will get all the words which are not assigned up to there.
I suggest you try the following to sunderstand the mechanism: create a file with the following content:
while read VAR1 VAR2 VAR3 ; do
echo VAR1=\"$VAR1\" VAR2=\"$VAR2\" VAR3=\"$VAR3\"
done < /path/to/input.file
As a final addition you can use/modify the shell-internal IFS-variable to influence the way the shell defines what a "word" is. Per default the IFS value is a space, which is why in the above example "word1" was going into one variable and "word2" into the next. Suppose you have this file:
first value here=second value here=third value here
you could read that in, split not at spaces but at equal signs like this:
while IFS="=" read VAR1 VAR2 VAR3 ; do
echo VAR1=\"$VAR1\" VAR2=\"$VAR2\" VAR3=\"$VAR3\"
done < /path/to/input.file
{ read X; while read SD US HN WM CM CC X
do cat <<EOF
define service{
service_description $SD
use $US
host name $HN
check_command check_ssh_disk!${WM}!${CM}!$CC
}
EOF
done; } < file
define service{
service_description disk-usage-tmp
use generic-service
host name test1
check_command check_ssh_disk!80!90!/tmp
}
define service{
service_description disk-usage-var
use generic-service
host name test1
check_command check_ssh_disk!80!90!/var
}
define service{
service_description disk-usage-data
use generic-service
host name test1
check_command check_ssh_disk!80!90!/data
}
@wbport: On my linux system, line closes stdin after reading one single line of text, so your proposal in post#2 will enter an infinite loop...