My input file content is
welcome
welcome1
welcome2
My script is
for groupline in `cat file`
do
echo $groupline;
done
I got the following output.
welcome welcome1 welcome2
Why it is not print the empty line. I want the reason.
My input file content is
welcome
welcome1
welcome2
My script is
for groupline in `cat file`
do
echo $groupline;
done
I got the following output.
welcome welcome1 welcome2
Why it is not print the empty line. I want the reason.
Because you're doing it all wrong. You want while
not for
, and you want read
, not cat
:
while read groupline
do
echo "$groupline"
done < file
you need to set IFS
to newline \n
IFS=$"\n"
for groupline in $(cat file)
do
echo "$groupline";
done
Or put double quotes. See here for explanation
for groupline in "$(cat file)"
do
echo "$groupline";
done
without meddling with IFS, the "proper" way is to use while read loop
while read -r line
do
echo "$line"
done <"file"