ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
My question deals with me creating a name pipe (file) in the my /group directory called chat.
I then have to write a script to read from the named pipe and save data into a file called chat.log until the words End of File are passed to the program.
-When I created the named pipe file (chat) I used the mknod chat p command..Is this the correct command to create a named pipe file?
-Then I'm having trouble with my script and how to make it run until the words End of File are entered in. This is what I have so far...
#!/bin/bash
The script is not putting any data into the chat.log file. Is it better if I use a while or until loop? I was thinking a until loop would be better since I want the script to run until the words End of File are passed to the program.But I'm not sure what would be the easiest or best way? Yes I have this for my one class I'm taking right now...I don't want you to give me the script or anything, I just wanted to get some help because I'm just getting into writing scripts..Thanks again.
In case the fifo does not exist or breaks, the best option is to use while read. The normal termination on reading "End of File" will have to come after the read (so you've got a line to examine) and before writing to file (because you don't want to write anything if you just read "End of File").
while read chat
do
if [[ "$chat" = 'End of File' ]]; then
break
else
chat >> chat.log
fi
done
I'm able to end the file now by typing "End of File" but I can't save the data into the chat.log file for some reason?? Any idea whys its not letting me? Thanks!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.