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.
Hello, I'm trying to write a bash script program in the Linux command terminal that will write to a fellow user and then continue reading down the program. this is what i have (kind of explains the idea too):
#!/bin/sh
clear
echo "this is before the write command"
write jcummins
this message should go to jerry
echo "the message didn't send and this string will not appear"
echo "it appears it has stopped at the write command"
I had never heard of the write command until this thread. But I figure, since other interactive stuff occurs in scripts, then why not? Though it really doesn't appear to need a script to be used, as it's kind of a one-shot deal:
Code:
sasha@reactor: w
23:43:54 up 18:58, 2 users, load average: 0.12, 0.08, 0.08
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
sasha tty2 - 04:47 18:54m 15:08 0.00s /bin/sh /usr/bin/startx
sasha pts/0 :0.0 23:38 0.00s 0.21s 0.06s /usr/bin/xterm -fn -misc-Fixed-Med
sasha@reactor: write sasha /dev/pts/0 << EOF
> jellooo
> EOF
causes this in my xterm:
Code:
Message from sasha@reactor on pts/0 at 23:44 ...
jellooo
EOF
sasha@reactor:
It appears to work assuming you know which console a user is logged in on (try the `w` command to see).
When I add a loop the program should send the message, "Hello Jerry!!" 5 times to jerry's terminal(assuming he is logged on to the server). But I keep getting this error: Syntax error: end of file unexpected (expecting "done")
I have tried everything and searched everywhere to find a solution and nothing has worked
any ideas? Thanks!
If that is the EXACT code that is in your script, then the problem is likely those ">" characters.
If you copied the code from my above example, then you should know that I just did that right in my console; this makes bash print the > character on the next line when it is waiting for more input.
Other than those > characters, I don't see a problem with your code (other than that you have not specified which tty or pty jerry might be logged into).
Also, for the record, EFO is usually "EOF" which stands for "End Of File", though if you like to use "EFO" you can certainly continue doing so; as long as the EOF and EOF at the start and end, are the same, it will work.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.