当前位置: 技术问答>linux和unix
shell脚本的read -p写法
来源: 互联网 发布时间:2017-01-10
本文导语: 一个脚本sh02.sh是: #!/bin/bash PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH read -p "Please input your first name: " firstname read -p "Please input your last name: " lastname echo -e "nYour full name is: $firstnam...
一个脚本sh02.sh是:
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
read -p "Please input your first name: " firstname
read -p "Please input your last name: " lastname
echo -e "nYour full name is: $firstname $lastname
但执行时提示sh02.sh: -p: is not an identifier
我直接在unix中敲read -p "Please input your first name: " firstname没有问题,请问是脚本哪里不对?
另外,当仅执行echo -e "nYour full name is: $firstname $lastname时显示一个:
-e
Your full name is:
这里-e怎么会打印出呢?
谢谢!
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
read -p "Please input your first name: " firstname
read -p "Please input your last name: " lastname
echo -e "nYour full name is: $firstname $lastname
但执行时提示sh02.sh: -p: is not an identifier
我直接在unix中敲read -p "Please input your first name: " firstname没有问题,请问是脚本哪里不对?
另外,当仅执行echo -e "nYour full name is: $firstname $lastname时显示一个:
-e
Your full name is:
这里-e怎么会打印出呢?
谢谢!
|
小伙子,你最好貌似没有加引号吧,我的执行结果如下:
[root@node2 ~]# sh aaaaaa.sh
Please input your first name: zhu
Please input your last name: ying
Your full name is: zhu ying
[root@node2 ~]# sh aaaaaa.sh
Please input your first name: zhu
Please input your last name: ying
Your full name is: zhu ying
|
最后一行的行尾少了个双引号
什么系统?
什么系统?
|
test.sh
#!/bin/bash
for ((i=1;i