1

我打算强调用户输入,但经过研究,我仍然找不到方法。

到目前为止,这是我从研究中得到的,但它仍然不起作用。任何人都知道如何解决它?或者更确切地说是正确的方法?

如果我使用read -p "What is your name:" 名称而不是下面的名称怎么办?正如我对输出的期望一样。

你叫什么名字?(来自用户的输入并带有下划线)

function underlineInput()
{
PS1='\033[4;47;40m'
}

function UNunderlineInput()
{
PS1='\033[0;47;40m'
}

function hi()
{
echo "Please enter your name: "
underlineInput
read input
underlineInput
}

感谢那些提前帮助的人!干杯!

4

2 回答 2

2

在此处查看此链接

但它只是:

$ echo -e "\033[4mThis is a underlined line.\033[0m"

关键部分是\033[4m下划线并将\033[0m其改回。

于 2012-01-30T15:05:21.680 回答
1

将转义序列放在提示符末尾打开下划线,然后发送返回正常序列:

read -p $'Please enter your name: \033[4m' name
printf '\033[0m' # Use printf instead of echo to avoid newline, and it translates escape without $''

顺便说一句,如果您希望此脚本也可以在其他类型的终端上运行,您可以使用 terminfo 数据库来获取相关的转义(/whatever)序列。用于打开和关闭下划线的 terminfo 功能名称是“smul”和“rmul”:

read -p "Please enter your name: $(tput smul)" name
tput rmul
于 2012-01-30T17:33:15.557 回答