如何用换行显示阅读提示 [英] How to show read prompt with a new line
本文介绍了如何用换行显示阅读提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用内置的 read
来读取变量,但是我想让输入出现在下一行,即提示输出了新行,但是两者都没有两部作品:
I'm using read
builtin to read a variable, but I'd like to let the input appears on the next line, that is, the prompt output a new line, but neither of the two works:
$ read -p "Please input:\n" name
Please input:\n
$ read -p 'Please input:\n" name
Please input:\n
如您所见,即使在双引号的情况下,新行换码序列也不会被解释.所以有办法吗?
As you see new line escape sequence is not interpreted even in the double quote case. So is there anyway to do that?
推荐答案
您可以将提示与实际阅读内容分开:
You can separate the prompt from the actual read :
echo "Please input:"
read name
您可以将它们放在一行上:
You can put both on a single line :
echo "Please input:" ; read name
您还可以使用其他形式的引号:
You can also use a different form of quoting :
read -p $'Please input\n' name
这只是短短一点,许多人可能会觉得它的可读性较差,但这是一个品味问题.
This is barely shorter, and many would probably find it a bit less readable, but that is a matter of taste.
这篇关于如何用换行显示阅读提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文