此处的字符串是否会分解单词? [英] Do here-strings undergo word-splitting?

查看:84
本文介绍了此处的字符串是否会分解单词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

引用 Bash参考手册(版本4.3):

Quoting Bash Reference Manual and man bash (version 4.3):

[n]<<< word

[n]<<< word

word 经历大括号扩展,代字号扩展,参数和 变量扩展,命令替换,算术扩展和 取消报价.路径名扩展和单词拆分不是 执行.

The word undergoes brace expansion, tilde expansion, parameter and variable expansion, command substitution, arithmetic expansion, and quote removal. Pathname expansion and word splitting are not performed.

word不应进行单词拆分.但是,使用以下简单代码:

The word should not undergo word-splitting. However, using this simple code:

var="a    b"

cat <<< $var
#output:
#a b

cat <<< "$var"
#output:
#a    b

我想念什么?这是否取决于bash的版本,或者手册中是否有错误?我正在使用GNU bash, version 4.3.48.

What am I missing? Does this depend on the version of bash or is there a mistake in the manual? I am using GNU bash, version 4.3.48.

推荐答案

在bash-4.4-alpha和bash-4.4-beta之间发生了从此处拆分字符串到不拆分的变化.引用自 CHANGES :

The change from splitting here-strings to not splitting them happened between bash-4.4-alpha and bash-4.4-beta. Quoting from CHANGES:

Bash不再像文档中一直说的那样分割here-strings的扩展.

Bash no longer splits the expansion of here-strings, as the documentation has always said.

因此,较早的Bash版本的手册中提到了它,但实际上并没有这样做.

So the manuals of older Bash versions mentioned it, but didn't actually do it.

这篇关于此处的字符串是否会分解单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆