简体   繁体   English

使用Wall向所有用户广播用户消息

[英]Broadcast User Message to All Using Wall

so I want to let the user enter a specific message either by pasting it or typing it themselves using wall and by using wall, broadcast it to all users. 因此,我想让用户输入特定的消息,方法是粘贴消息,或者使用wall自己键入消息,然后使用wall广播给所有用户。 I the idea is that I don't want to have only one line of message but rather allow for as big of a message that they want without using a text file. 我的想法是,我不想只显示一行消息,而是在不使用文本文件的情况下允许他们想要的尽可能多的消息。

I came up with this: 我想出了这个:

...
elif [ $var -eq 3 ]

        echo "Enter your broadcast message (When done, wait 2 seconds):"
        broadcastThis= read -d '' -n 1 message

        while broadcastThis=`read -d '' -n 1 -t 2 c`
        do
            message+=$c
        done

        wall <<< $message
fi

I get an error stating the following: 我收到一条错误消息,指出以下内容:

script: line 146: warning: here-document at line 141 delimited by end-of-file (wanted `$message') script: line 147: syntax error: unexpected end of file 脚本:第146行:警告:此处文档位于第141行,由文件结尾定界(需要`$ message')脚本:第147行:语法错误:文件意外结束

I am really stuck at this point, it seems to have an issue on how wall is taking in the variable $message. 我真的被困在这一点上,似乎墙如何接受变量$ message存在问题。

EDIT: I made the changes that devnull suggested but now only the first letter of the user's input is being broadcasted. 编辑:我做了devnull建议的更改,但现在只广播用户输入的第一个字母。

<< denotes a here document . <<表示此处文档

What you're looking for is a herestring: 您要查找的是一个herestring:

wall <<< "$message"

If you wanted a here document, you'd need to use the correct syntax: 如果您需要此处文档,则需要使用正确的语法:

wall << DELIMITER
"$message"
DELIMITER

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM