Med*_* Gh 3 linux bash shell newline
我怎么能使用断行\n的read -p?
例如
read -p "Please Enter the percent [30 between 100]\n The value is Default = 80 :" scale_percent
Run Code Online (Sandbox Code Playgroud)
我想\n打破一条线,但它不起作用.
在echo我使用-e它,它打破了一条线.
所以我试过了
read -ep
Run Code Online (Sandbox Code Playgroud)
打破界限,但没有打破界限.我怎样才能做到这一点?
你read -p能不能在互联网上给我一本好的手册,因为我找不到一个好的,没有令人困惑的描述.
你可以这样做:
read -p $'Please Enter the percent [30 between 100]\x0a The value is Default = 80 :' scale_percent
Run Code Online (Sandbox Code Playgroud)
我们使用上面的语法来插入十六进制值,我们插入的\x0a是换行符(LF)的十六进制值.您可以使用上面的相同语法echo来生成新行,例如:
echo $'One line\x0asecond line'
Run Code Online (Sandbox Code Playgroud)
这是BASH 2的一个特性,它在这里有记载,$''用于翻译其中的所有转义序列以进行ascii转录.因此,我们可以通过以下方式获得上述示例的相同结果:
echo $'One line\nsecond line'
Run Code Online (Sandbox Code Playgroud)