shell脚本的read -p写法

一个脚本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怎么会打印出呢?

谢谢!

第1个回答  2011-10-13
关於第一个问题:-p: is not an identifier
有可能是因为你的PATH的设定。
你可以在第一个read之前加一行
type read
看看这个read是从哪里来的
同时直接在你的Unix prompt里也输入type read看看结果
应该得到的是同样的答案(read is a shell builtin)

Good Luck!追问

确实是“read is a shell builtin”这个回显,这是什么意思?

第2个回答  2011-10-17
加一句 set /p追问

在命令行里敲了set /p,还是如此的。

追答

那真不清楚了,我这边都一切正常。

第3个回答  2011-10-10
echo -e "\nYour full name is: $firstname $lastname"

少个冒号追问

修改为echo -e "\nYour full name is: $firstname $lastname",还是如此

追答

也不知道,你怎么写的,我直接复制你上边写的,加个冒号就行了。
[flycat@redhat script]$ chmod 755 aaa.sh
[flycat@redhat script]$ ./aaa.sh
Please input your first name: 4
Please input your last name: 3

Your full name is: 4 3

本回答被提问者采纳
第4个回答  2011-10-14
我也遇到同样的问题了,期待答案!
第5个回答  2011-10-10
echo $SHELL 看一下你使用的是哪个shell
然后再修改脚本中的头文件追问

是/usr/bin/ksh,文件头修改为/usr/bin/ksh后还是如此

追答

这个就不知道了 Unix没玩过 shell也只用bash 不好意思

相似回答