Discussion Locked

Shell script !

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I'm trying to create an unix script shell for reading a file with this text:

Example:
1 Error log not found!
2 Error on file!
3 Error on permissions!

And this my script shell:

A='cat file'
for in in $A
do
echo $i
done

the information displayed on my screen is this:
1
Error
log
not
found!
2
Error
on
file!
3
Error
on
permissions!

And what I need is the information displayed in the followinf format:
1 Error log not found!
2 Error on file! 3 Error on permissions!

How can I keep it together or just the message in the variable.

Thank you for your help

3 replies

by steve cody

What shell are you using? This is how you do it in KSH. It may work with other shells as well, and it is probably the same concept. You need to change the Initial Field Separator (IFS) value to a CR/LF, or whatever the ^J is.

This will work for you with ksh.

For the first line below, enter the first ' then press CTRL-J. It will move the cursor to the next line. Then enter the closing '. That will take care of it. You won't actually see a ^J appear on your screen, I don't think. Maybe you will if you are entering it in VI.

export IFS='^J'
A='cat file'
for i in $A
do
echo $i
done

This discussion is closed to new replies.