如何在read -p
中使用\n
换行?
例如
read -p "Please Enter the percent [30 between 100]\n The value is Default = 80 :" scale_percent
我想要\n
打破一条线,但它不起作用。
在echo
中,我使用-e
,它会中断一行。
所以我试着
read -ep
去打破这条线,但它并没有打破这条线。我该怎么做呢?
你能不能在网上给我一本好的read -p
手册,因为我找不到一本没有令人困惑的描述的好手册。
发布于 2012-10-05 07:33:50
你可以这样做:
read -p $'Please Enter the percent [30 between 100]\x0a The value is Default = 80 :' scale_percent
我们使用上面的语法来插入十六进制值,我们插入\x0a
,它是换行符(LF)的十六进制值。您可以在echo
中使用上面相同的语法来生成新行,例如:
echo $'One line\x0asecond line'
这是Bash2的一个特性,它记录了here,,$''
被用来翻译它内部的所有转义序列,用于它的ascii转录。因此,我们可以通过这种方式获得与上面示例相同的结果:
echo $'One line\nsecond line'
https://stackoverflow.com/questions/12741529
复制相似问题