for line in $(cat $1) ; do echo $line echo "["$line"]" echo "*"${line}"*" done
unfortunately, and for reasons unknown to me it doesn't work properly on lines with a space in.
The reason is the IFS variable setting.
The $(cat $1) statement expands to a whole series of things, separated by spaces, newlines and tabs. IFS by default treats all these as being equivalent, hence the "spaces are the same as newlines" problem.
As was posted later, setting IFS to contain just a newline IFS=' ' means that spaces (and tabs) are no longer treated as field separators.
perl doesn't do this :-
[EMAIL PROTECTED]:~$ perl -e 'while (<>) {chomp;print "$_\n[$_]\n*$_*\n"}'
fred
fred
[fred]
*fred*
foo bar
foo bar
[foo bar]
*foo bar*Still, it sounds like another homework question to me. Is someone running through an "introduction to unix" course somewhere?
-jim
