免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3224 | 回复: 8
打印 上一主题 下一主题

[学习共享] bash-4.4 here string 处理的变化(or bug?) [复制链接]

论坛徽章:
84
每日论坛发贴之星
日期:2015-12-29 06:20:00每日论坛发贴之星
日期:2016-01-16 06:20:00每周论坛发贴之星
日期:2016-01-17 22:22:00程序设计版块每日发帖之星
日期:2016-01-20 06:20:00每日论坛发贴之星
日期:2016-01-20 06:20:00程序设计版块每日发帖之星
日期:2016-01-21 06:20:00每日论坛发贴之星
日期:2016-01-21 06:20:00程序设计版块每日发帖之星
日期:2016-01-23 06:20:00程序设计版块每日发帖之星
日期:2016-01-31 06:20:00数据库技术版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-14 06:20:00
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2017-11-22 10:45 |只看该作者 |倒序浏览
  1. '''
  2. [yjh@bash4.4 ~]$ LANG=C bash --version|head -n1
  3. GNU bash, version 4.4.12(1)-release (x86_64-redhat-linux-gnu)
  4. [yjh@bash4.4 ~]$ read a <<<$(echo -e "foo\t\tbar"); echo "$a"
  5. foo        bar
  6. '''
复制代码

  1. '''
  2. [yjh@bash4.2 ~]$ bash --version|head -n1
  3. GNU bash, version 4.2.46(1)-release (x86_64-redhat-linux-gnu)
  4. [yjh@bash4.2 ~]$ read a <<<$(echo -e "foo\t\tbar"); echo "$a"
  5. foo bar
  6. '''
复制代码



  1. '''
  2. [root@bash-3.2 ~]# bash --version
  3. GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu)
  4. Copyright (C) 2005 Free Software Foundation, Inc.
  5. [root@bash-3.2 ~]# read a <<<$(echo -e "foo\t\tbar"); echo "$a"
  6. foo bar
  7. '''
复制代码


  1. '''
  2. [root@bash-4.1 ~]# bash --version
  3. GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
  4. Copyright (C) 2009 Free Software Foundation, Inc.
  5. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

  6. This is free software; you are free to change and redistribute it.
  7. There is NO WARRANTY, to the extent permitted by law.
  8. [root@bash-4.1 ~]# read a <<<$(echo -e "foo\t\tbar"); echo "$a"
  9. foo bar
  10. '''
复制代码


论坛徽章:
2
射手座
日期:2014-10-10 15:59:4715-16赛季CBA联赛之上海
日期:2016-03-03 10:27:14
2 [报告]
发表于 2017-11-22 17:14 |只看该作者
回复 1# yjh777

和<<<好像没有关系,echo "$a" 和 echo $a 的区别

论坛徽章:
84
每日论坛发贴之星
日期:2015-12-29 06:20:00每日论坛发贴之星
日期:2016-01-16 06:20:00每周论坛发贴之星
日期:2016-01-17 22:22:00程序设计版块每日发帖之星
日期:2016-01-20 06:20:00每日论坛发贴之星
日期:2016-01-20 06:20:00程序设计版块每日发帖之星
日期:2016-01-21 06:20:00每日论坛发贴之星
日期:2016-01-21 06:20:00程序设计版块每日发帖之星
日期:2016-01-23 06:20:00程序设计版块每日发帖之星
日期:2016-01-31 06:20:00数据库技术版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-14 06:20:00
3 [报告]
发表于 2017-11-22 17:38 |只看该作者

你好好看看,实测一下再说

论坛徽章:
84
每日论坛发贴之星
日期:2015-12-29 06:20:00每日论坛发贴之星
日期:2016-01-16 06:20:00每周论坛发贴之星
日期:2016-01-17 22:22:00程序设计版块每日发帖之星
日期:2016-01-20 06:20:00每日论坛发贴之星
日期:2016-01-20 06:20:00程序设计版块每日发帖之星
日期:2016-01-21 06:20:00每日论坛发贴之星
日期:2016-01-21 06:20:00程序设计版块每日发帖之星
日期:2016-01-23 06:20:00程序设计版块每日发帖之星
日期:2016-01-31 06:20:00数据库技术版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-14 06:20:00
4 [报告]
发表于 2017-11-22 17:47 |只看该作者
bash-4.4 上 <<<  右面的所有内容,都不会通过 IFS 切割了

<<<$var  跟以前的  <<<"var"  一个效果

论坛徽章:
25
程序设计版块每日发帖之星
日期:2016-05-03 06:20:0015-16赛季CBA联赛之八一
日期:2018-07-05 10:34:09黑曼巴
日期:2018-07-06 15:19:5015-16赛季CBA联赛之佛山
日期:2018-08-03 13:19:3315-16赛季CBA联赛之山西
日期:2018-08-07 19:46:2315-16赛季CBA联赛之广夏
日期:2018-08-08 19:31:5015-16赛季CBA联赛之青岛
日期:2018-11-26 15:21:5015-16赛季CBA联赛之上海
日期:2018-12-11 09:45:3219周年集字徽章-年
日期:2020-04-18 23:54:5215-16赛季CBA联赛之深圳
日期:2020-04-19 21:40:19黑曼巴
日期:2022-04-03 17:55:1315-16赛季CBA联赛之八一
日期:2018-07-03 16:56:46
5 [报告]
发表于 2017-11-22 19:33 |只看该作者
回复 1# yjh777


不同shell版本之间存在差异也正常,zsh 4.3.11上测试结果和bash 4.4.12一样,为了兼容不同版本的shell,给变量赋值时最好采用赋值语句:
a="$(echo -e "foo\t\tbar")"&&echo "$a"
如果一定要用hear string,也加上双引号吧:
read a <<< "$(echo -e "foo\t\tbar")"&&echo "$a"

论坛徽章:
2
射手座
日期:2014-10-10 15:59:4715-16赛季CBA联赛之上海
日期:2016-03-03 10:27:14
6 [报告]
发表于 2017-11-23 17:33 |只看该作者
回复 1# yjh777

找到了:
This document details the changes between this version, bash-4.4-beta, and
the previous version, bash-4.4-alpha.

1.  Changes to Bash

a.  Fixed two bugs that caused out-of-bounds reads when skipping over assignment
    statements while finding the word on which to perform programmable
    completion.

b.  Fixed a memory leak in programmable completion.

c.  Fixed a bug that could cause the shell to crash when interrupting the
    wait builtin.

d.  Fixed a bug that caused ${!vvv@} to be interpreted as introducing the new
    `@' operator.

e.  Fixed a bug that caused the && and || operators to be incorrectly optimized.

f.  The shell now undoes redirections before exiting the shell when the `-e'
    option is enabled, and a shell function fails.

g.  History expansion now skips over the history expansion character in command
    and process substitution.

h.  Fixed a bug that caused stray '\001' characters to be added to the output
    of `declare -p'.

i.  Fixed a memory leak when processing declare commands that perform compound
    array assignments.

j.  Fixed a bug that could cause the shell to crash when reading input from a
    file and the limit on open file descriptors is high.

k.  Fixed a bug that caused the ERR and RETURN traps to be unset if they were
    set in a shell function but unset previously.

l.  Fixed a bug that caused several signals to be ignored if `exec' failed in
    an interactive shell.

m.  A posix-mode non-interactive shell now considers a parameter expansion error
    to be a fatal error.

n.  The `time' command now prints timing statistics for failed commands when
    the -e option is enabled.

o.  Fixed a bug that caused the shell to crash when attempting to indirectly
    expand a shell variable with an invalid name.

p.  Fixed a bug that caused the shell to crash when running a trap containing
    a process substitution.

q.  Bash now prints the keyword `function' before a function with the same name
    as a reserved word when using `declare -f' to avoid parse errors when
    reusing the output as input.

r.  Fixed a bug that caused the shell to crash when using declare -g to attempt
    to redefine an existing global indexed array variable as an associative
    array.

s.  Fixed a memory leak that occurred when interrupting brace expansions
    generating a sequence.

t.  Fixed a bug that resulted in alias expansion in redirections.

u.  The `declare -a' and `declare -A' commands now print fewer warnings when
    attempting to create and initialize an array at the same time, but
    relying on word expansions to construct the compound assignment.

v.  The `help' builtin now behaves better in locales where each wide
    character occupies more than one display column.

w.  The `read' builtin no longer has a possible race condition when a timeout
    occurs.

x.  Fixed several expansion problems encountered when IFS="'".

y.  Fixed a problem with the expansion of $'\c?'.

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

aa. Bash now puts `s' in the value of $- if the shell is reading from standard
    input, as Posix requires.

bb. Fixed a bug that caused the shell to crash if invoked with a NULL
    environment.

cc. The shell now only trusts an inherited value for $PWD if it begins with a
    `/'.

dd. Fixed a memory leak when creating local array variables and assigning to
    them using compound assignment with the `declare' builtin.

ee. Fixed a bug that could cause the shell to crash when processing nested here
    documents inside a command substitution.

ff. Array keys and values are now displayed using $'...' quoting where
    appropriate.

gg. Fixed a bug that could cause the shell to crash if the replacement string
    in pattern substitution was NULL.

hh. Fixed a bug that could cause the shell to crash if a command substitution
    contained a non-fatal syntax error.

ii. Fixed a bug that could cause the shell to crash if variable indirection
    resulted in a NULL variable.

jj. Fixed a bug that could cause the shell to crash if a long string contained
    multiple unterminated parameter expansion constructs.

kk. Improved the code that acts on SIGINT received while waiting for a child
    process only if the child exits due to SIGINT.

ll. $BASH_SUBSHELL now has more consistent values in asynchronous simple
    commands.

论坛徽章:
84
每日论坛发贴之星
日期:2015-12-29 06:20:00每日论坛发贴之星
日期:2016-01-16 06:20:00每周论坛发贴之星
日期:2016-01-17 22:22:00程序设计版块每日发帖之星
日期:2016-01-20 06:20:00每日论坛发贴之星
日期:2016-01-20 06:20:00程序设计版块每日发帖之星
日期:2016-01-21 06:20:00每日论坛发贴之星
日期:2016-01-21 06:20:00程序设计版块每日发帖之星
日期:2016-01-23 06:20:00程序设计版块每日发帖之星
日期:2016-01-31 06:20:00数据库技术版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-14 06:20:00
7 [报告]
发表于 2017-11-27 10:34 |只看该作者
回复 6# yinyuemi

赞!我刚开始只搜了 here string ,没想到它用的是 here-string;

问了一下开发,说是以前的处理算bug. current behavior matches the behavior of ksh and zsh ;

论坛徽章:
1
摩羯座
日期:2014-12-29 15:59:36
8 [报告]
发表于 2017-12-04 15:16 |只看该作者
Here String 中不该进行分词 www.cnblogs.com/ziyunfei/p/4781553.html

论坛徽章:
84
每日论坛发贴之星
日期:2015-12-29 06:20:00每日论坛发贴之星
日期:2016-01-16 06:20:00每周论坛发贴之星
日期:2016-01-17 22:22:00程序设计版块每日发帖之星
日期:2016-01-20 06:20:00每日论坛发贴之星
日期:2016-01-20 06:20:00程序设计版块每日发帖之星
日期:2016-01-21 06:20:00每日论坛发贴之星
日期:2016-01-21 06:20:00程序设计版块每日发帖之星
日期:2016-01-23 06:20:00程序设计版块每日发帖之星
日期:2016-01-31 06:20:00数据库技术版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-14 06:20:00
9 [报告]
发表于 2017-12-20 16:15 |只看该作者
ziyunfei 发表于 2017-12-04 15:16
Here String 中不该进行分词 www.cnblogs.com/ziyunfei/p/4781553.html

嗯,知道了。

下次发现这种问题最好直接report到上游去,像这样(如果只写在自己博客里,被看到和修复的可能性太小了):
  http://lists.gnu.org/archive/html/bug-bash/2015-09/msg00022.html
  http://lists.gnu.org/archive/html/bug-bash/2017-11/msg00104.html

  http://lists.gnu.org/archive/html/bug-bash/2017-11/msg00118.html
  http://lists.gnu.org/archive/htm ... /threads.html#00099

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP