2014-05-05 37 views
0

所以我想讓用戶輸入一個特定的消息,通過粘貼或使用牆壁和使用牆壁自己輸入,將其廣播給所有用戶。我的想法是,我不希望只有一行消息,而是允許在不使用文本文件的情況下儘可能地傳達他們想要的消息。廣播用戶消息給所有使用牆

我想出了這一點:

... 
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 

我得到一個錯誤,說明如下:

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

我真的停留在這一點上,似乎對牆壁如何是一個問題接受變量$消息。

編輯: 我做了devnull建議的更改,但現在只播放用戶輸入的第一個字母。

回答

1

<<表示here document

什麼你要找的是一個herestring:

wall <<< "$message" 

如果你想立即文檔,你需要使用正確的語法:

wall << DELIMITER 
"$message" 
DELIMITER 
+0

是啊是擺脫了錯誤,但現在它只播放用戶輸入的第一個字母,然後是echo聲明... – bloodstorm17

+0

@ bloodstorm17將while循環更改爲:while read -d'-n 1 -t 2 c'並移除' broadcastThis ='也來自第一個'read'命令。 – devnull