-   Programming (
-   -   "write" bash command (

i_have_a_question 03-22-2010 08:51 PM

"write" bash command
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):


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"

please help me,

grail 03-22-2010 09:18 PM

Well I cannot say I have used this command, but I did find the following:


Since write is interactive, it would not normally find use in a script.

GrapefruiTgirl 03-22-2010 09:32 PM

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:


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

causes this in my xterm:

Message from sasha@reactor on pts/0 at 23:44 ...

It appears to work :) assuming you know which console a user is logged in on (try the `w` command to see).


i_have_a_question 03-23-2010 07:18 AM

THANK YOU! you are amazing!

i_have_a_question 03-23-2010 08:54 PM

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!




x=1 # this sets up the flag so we can have it send a limited amount

while [ $x -le 5 ]
write jcummins << EFO
>Hello Jerry!!
x=$(( $x + 1 ))

GrapefruiTgirl 03-23-2010 09:45 PM

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.


All times are GMT -5. The time now is 09:37 AM.