macos – “echo -n”在使用bash执行脚本时工作正常,但不能用sh执行

与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.

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...