How do I add a line break for read command?

前端 未结 7 632
孤街浪徒
孤街浪徒 2020-12-24 10:43
 read -p \"Please Enter a Message:\" message

How can I add a line break after Message:?

7条回答
  •  天涯浪人
    2020-12-24 11:14

    Here's an improvement on the accepted answer that doesn't require spawning a subshell:

    read -p "Please Enter a Message:"$'\n' message
    

    From the GNU Bash reference manual:

    Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard.

提交回复
热议问题