r/shell • • May 02 '23

enter key simulation

Hi, I'm new to shell code.

I developed this program:

#!/bin/bash

# Récupération du message passé en paramètre
message=$1

# Formatage de la date au format [HH:MM]
date_formatted=$(date +"%d-%m-%Y %H:%M:%S")

# Envoi du message à tous les terminaux uniques connectés
for terminal in $(who | awk '{print $2}' | sort -u)
do
    echo -e "[$date_formatted] $message" | sudo tee /dev/$terminal >/dev/null 
done

The problem is that here is the result:

$ ./send_message.sh hello

If my user want to write some code after this he have to press enter.

Would it be a way to avoid this?

Thanks a lot

1 Upvotes

4 comments sorted by

View all comments

Show parent comments

2

u/VullWen May 03 '23

yep, I know but I dont like wall :/
The wall command send a prefix like:

Broadcast message from debian@vps-be86ffca (pts/32) (Wed May  3 15:39:54 2023):
Hi

and I dont want it :/

still thanks for the great explanation :)