加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-15 18:32:22 所属栏目:安全 来源:网络整理
导读:与bash UsersInput.sh相比,为什么sh来自UsersInput.sh会提供不同的输出? 我的脚本如下: #!/bin/bashecho -n "Enter: ";read usersinput;echo "You entered,"$usersinput""; 庆典 localhost:Bash henry$bash UsersInput.sh Enter: inputYou entered,"inpu
与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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读