簡體   English   中英

BASH:當讀取用戶輸入時,Enter帶來新行

[英]BASH: When reading user input, Enter brings new line

我需要以下示例bash腳本,行為如下:

echo -e "Enter name: \c"
read U_IP_NAME
echo -e "You said your name is : $U_IP_NAME"

這將輸出到:

Enter name: Alok
You said your name is : Alok

但我希望它是:

You said your name is : Alok

有沒有辦法實現這個目標?

[解決方案:mouviciel]

您想將光標向上移動一行。 這是通過tput cuu1實現的:

echo -e "Enter name: \c"
read U_IP_NAME

tput cuu1

echo -e "Your said your name is : $U_IP_NAME"

更多信息與man tputman terminfo

read -p "Enter your uip-name: " U_IP_NAME

-p用於提示

您可以嘗試以下語法

U_IP_NAME = “$ {U_IP_NAME%\\\\ N}”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM