![](/img/trans.png)
[英]Reading user command line input with PHP with readline, but bash is not default shell
[英]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 tput
和man 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.