bash – 这里的字符串添加换行符

看来这里的字符串是添加换行符.有没有方便的删除方法?
$string='test'
$echo -n $string | md5sum
098f6bcd4621d373cade4e832627b4f6  -
$echo $string | md5sum
d8e8fca2dc0f896fd7cb4cb0031ba249  -
$md5sum <<<"$string"
d8e8fca2dc0f896fd7cb4cb0031ba249  -
是的,你是对的:<<<添加一个尾随的新行. 你可以看到它:
$cat - <<< "hello" | od -c
0000000   h   e   l   l   o  \n
0000006

让我们将其与其他方法进行比较:

$echo "hello" | od -c
0000000   h   e   l   l   o  \n
0000006
$echo -n "hello" | od -c
0000000   h   e   l   l   o
0000005
$printf "hello" | od -c
0000000   h   e   l   l   o
0000005

所以我们有桌子:

| adds new line |
-------------------------|
printf   |      No       |
echo -n  |      No       |
echo     |      Yes      |
<<<      |      Yes      |

Why does a bash here-string add a trailing newline char?开始:

Most commands expect text input. In the unix world,07001.
So in most cases a final newline is required. An especially common
case is to grab the output of a command with a command susbtitution,
process it in some way,then pass it to another command. The command
substitution strips final newlines; <<< puts one back.

相关文章

用的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补全...