Mac Shell脚本中使用echo的-n参数不生效

Mac Shell脚本中使用echo -n导入文件无法实现不换行,在Linux服务器上未发现此问题
问题代码test.sh
#!/bin/bash

test_file="tmp"

echo -n "line1" > ${test_file}
echo -n "line2" >> ${test_file}
echo -n "line3" >> ${test_file}
#/bin/echo -n "line1" > ${test_file}
#/bin/echo -n "line2" >> ${test_file}
#/bin/echo -n "line3" >> ${test_file}
问题复现

使用命令在mac上执行: sh test.sh
查看文件tmp如下,不能实现不换行并且信息打印有误:

-n line1
-n line2
-n line3
解决方法

1.将echo替换为/bin/echo,即在示例脚本中注释掉内容
2.执行脚本时使用命令bash test.sh
3.给脚本执行权限,直接执行./test.sh

参考

https://stackoverflow.com/questions/11675070/makefile-echo-n-not-working

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值