与bash UsersInput.sh相比,为什么sh来自UsersInput.sh会提供不同的输出?
我的脚本如下:
#!/bin/bash echo -n "Enter: "; read usersinput; echo "You entered,\"$usersinput\"";
庆典
localhost:Bash henry$bash UsersInput.sh Enter: input You entered,"input"
SH
localhost:Bash henry$sh UsersInput.sh -n Enter: input You entered,"input"
为什么-n与第一个表现正常,而第二个表现不正常?这是什么原因,是否有解决方法?
从男人回声:
Some shells may provide a builtin echo command which is similar or identical to this utility. Most notably,the builtin echo in sh(1) does not accept the -n option. Consult the builtin(1) manual page.
在bash中,Bourne-again shell,echo接受-n选项,而在sh中,Bourne shell,echo不接受,所以它只是回显你写的所有东西,包括-n.