标签:code bin none bottom read 变量 ott ret justify
普通方式:#! /bin/bashecho "Please enter your name:"read nameecho "Your name is $name ."123456
结果:
[root@yveshe ~]# ./jiaohu.sh Please enter your name:
Yves
Your name is Yves .
[root@yveshe ~]# 12345
下面用两种方式来解决用户输入的值和提示语在同行显示:
在普通的方式上添加-n
参数既可:
#! /bin/bashecho -n "Please enter your name:" #-n 代表不换行read nameecho "Your name is $name ."123456
结果:
[root@yveshe ~]# ./jiaohu.sh Please enter your name:yves
Your name is yves .
[root@yveshe ~]# 1234
将输入的提示语句下载read中,并添加参数-p
#! /bin/bashread -p "Please enter your name:" name #将用户输入的值保存到变量name中echo "Your name is $name ."1234
结果:
[root@yveshe ~]# ./jiaohu.sh Please enter your name:yves
Your name is yves .
[root@yveshe ~]#
Shell| 输入交互时,输入结果与提示语句在同一行显示
标签:code bin none bottom read 变量 ott ret justify
原文地址:http://blog.51cto.com/12553708/2149054