Normal way:
#! /bin/bashecho "Please enter your name:" Read Nameecho "your name is $name." 123456
result:
[Email protected] ~]#./jiaohu.sh Please enter your name:yvesyour name is Yves. [[email protected] ~]# 12345
The following two ways to resolve user input values and prompts in the peer display:
In the ordinary way add -n
parameter can be either:
#! /bin/bashecho -n "Please enter your name:" #-n Represents a non-newline read nameecho "your name is $name ." 123456
result:
[Email protected] ~]#./jiaohu.sh Please enter your Name:yvesyour name is Yves. [[email protected] ~]# 1234
Download the prompt statement to read and add the parameter -p
#! /bin/bashread -p "Please enter your name:" name #将用户输入的值保存到变量name中echo "your name is $name ." 1234
result:
[Email protected] ~]#./jiaohu.sh Please enter your Name:yvesyour name is Yves. [Email protected] ~]#
shell| When you enter an interaction, the input results are displayed on the same line as the prompt statement