Bash 读取输入 - 按 Tab 键切换提示符

use*_*045 5 bash

我有一个正在读取用户输入的脚本。这是我的代码:

if [ -z $volreadexists ]; then
        echo -e "\tThis will overwrite the entire volume (/dev/vg01/$myhost)...are you sure?"
        read REPLY
        echo
        if [[ $REPLY =~ ^[Yy]$ ]]; then
            echo -e "\t\tContinuing"
            syncvolume
        else
            echo "Fine...skipping"
        fi
    fi
Run Code Online (Sandbox Code Playgroud)

我必须使用,read REPLY因为read它本身不插入选项卡。我正在寻找类似的东西:

read -p "\tDoes this look OK? (n for No)" -n 1 -r
Run Code Online (Sandbox Code Playgroud)

\t在阅读提示上按 Tab 键。

如何向阅读提示添加选项卡?

更新:感谢@gniourf 的精彩回答!:

read -p $'\tDoes this look OK? (n for No)' -n 1 -r
Run Code Online (Sandbox Code Playgroud)

然而,我发现了一个问题。当我尝试在那里使用变量时,它不会翻译它:

read -p $'\tThis will overwrite the entire volume (/dev/vg01/$myhost)...are you sure? ' -n 1 -r
Run Code Online (Sandbox Code Playgroud)

变成

        This will overwrite the entire volume (/dev/vg01/$myhost)...are you sure?
Run Code Online (Sandbox Code Playgroud)

我想要的地方:

        This will overwrite the entire volume (/dev/vg01/server1)...are you sure?
Run Code Online (Sandbox Code Playgroud)

使用双引号也不起作用:(

有任何想法吗?

use*_*045 0

我最终参考了这个答案:

读取 bash 中具有默认值的变量

并创建了一个解决方法。它并不完美,但它有效:

myhost="server1"
if [ -z $volreadexists ]; then
    read -e -i "$myhost" -p $'\tJust checking if it\'s OK to overwrite volume at /dev/vg01/'
    echo
    if [[ $REPLY =~ ^$myhost[Yy]$ ]]; then
        echo -e "\t\tContinuing"
    else
        echo "Fine...skipping"
    fi
fi
Run Code Online (Sandbox Code Playgroud)