如何为读取命令添加换行符? [英] How do I add a line break for read command?
本文介绍了如何为读取命令添加换行符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
read -p "Please Enter a Message:" message
如何在Message:
之后添加换行符?
How can I add a line break after Message:
?
推荐答案
I like Huang F. Lei's answer, but if you don't like the literal line break, this works:
read -p "Please Enter a Message: `echo $'\n> '`" message
显示:
Please Enter a Message:
> _
...其中_
是光标结束的位置.请注意,由于通常在命令替换过程中会删除尾随的换行符,因此我在之后添加了>
.但是实际上,您最初的问题似乎不需要提示,所以:
...where _
is where the cursor ends up. Note that since trailing newlines are usually dropped during command substitution, I've included the >
afterward. But actually, your original question doesn't seem to want that prompt bit, so:
# Get a carriage return into `cr` -- there *has* to be a better way to do this
cr=`echo $'\n.'`
cr=${cr%.}
# Use it
read -p "Please Enter a Message: $cr" message
显示
Please Enter a Message:
_
不过,必须有更好的方法.
There has to be a better way, though.
这篇关于如何为读取命令添加换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文