Linux – How to send a message to another user via Bash

How to send a message to another user via Bash… here is a solution to the problem.

How to send a message to another user via Bash

I’m writing a shell script and I need to send messages to other users.

If I write to write user1 in trem,

then write the message and use Ctrl + D, the message will be successfully sent to the trem of user1.

But I want to automatically send a message to user1 with a .sh file, I’m having a problem. Every time you use the command write user1, you need to write a message yourself.

Now I want to save the message in a script and I don’t need to rewrite the message every time I send it. What should I do?

Solution

You can pipe a file/string into it

echo "message" | write <user>

Related Problems and Solutions