Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 如何在窗口底部设置一条线,并且不';t使用“时打印carrige return”;读取值“;?_Bash_Shell_Sh - Fatal编程技术网

Bash 如何在窗口底部设置一条线,并且不';t使用“时打印carrige return”;读取值“;?

Bash 如何在窗口底部设置一条线,并且不';t使用“时打印carrige return”;读取值“;?,bash,shell,sh,Bash,Shell,Sh,我正在做一个小的bash聊天。因此,我希望在窗口的底部有一行,用户可以在其中输入他的消息。当他按下“回车”键时,信息被发送并打印在最后一行的正上方。这条线不能动!像这样 User A sent: xxxx User B sent: xxxx User C sent: xxxx User A sent: xxxx User B sent: xxxx Write your message here : YYYY *hit enter* ===============================

我正在做一个小的bash聊天。因此,我希望在窗口的底部有一行,用户可以在其中输入他的消息。当他按下“回车”键时,信息被发送并打印在最后一行的正上方。这条线不能动!像这样

User A sent: xxxx
User B sent: xxxx
User C sent: xxxx
User A sent: xxxx
User B sent: xxxx
Write your message here : YYYY  *hit enter*
================================================
User A sent: xxxx
User B sent: xxxx
User C sent: xxxx
User A sent: xxxx
User B sent: xxxx
You: YYYY
Write your message here : 
我使用
readuserinput
获取输入,但当他按“回车”发送消息时,会出现换行符

所以我试了一下:

echo-e“\033[2A”#光标向上移动两行;echo-en“\r$i”#删除回车符;

我写了“你好”和“再见”这是怎么回事!我不知道怎么解决这个问题。有人有解决办法吗?谢谢

Helloge: Hello
Byesage: Bye
message:

我建议您查看一下。您需要的是将光标向右移动
\033[9C
,如下所示:

echo -e "\033[2A\033[9C$var_with_text_here"
如果这不是您真正需要的,请更好地解释,我将编辑我的答案:)

例如:

[user@host ~]$ echo "Message: bla"
Message: Hello
[user@host ~]$ echo -e "\033[2A\033[9CHello"

我查了一下滑块的运动,我对你的代码做了一点修改,得到了我想要的

while true; do
echo -e "message: \c"
read usermess
echo -e "\033[1A\033[1D====>  Your message: $usermess"
done
输出:

====>  Your message: Hello
====>  Your message: Hey
message: Welcome
感谢您的反馈