当前位置: 技术问答>linux和unix
awk 命令 标准输出作为数据源问题
来源: 互联网 发布时间:2017-03-30
本文导语: test.js 文件内容 viewport.js+touchXY.js+slider.js=temp/new.js define.js+common.js=temp/c.js config=$( cat build.config.ini | tr -d ' ' ) 命令:echo $config | awk 'NR==1{print $2}' 输出:define.js+common.js=temp/c.js //@1 命令:awk 'N...
test.js 文件内容
viewport.js+touchXY.js+slider.js=temp/new.js
define.js+common.js=temp/c.js
config=$( cat build.config.ini | tr -d ' ' )
命令:echo $config | awk 'NR==1{print $2}'
输出:define.js+common.js=temp/c.js //@1
命令:awk 'NR==1{print $2}' build.config.ini //@2
输出:空
为什么@2 正常输出为空 而@1确不行
标准输出作为数据源在这里面有什么问题吗? 很迷惑
先谢谢了
viewport.js+touchXY.js+slider.js=temp/new.js
define.js+common.js=temp/c.js
config=$( cat build.config.ini | tr -d ' ' )
命令:echo $config | awk 'NR==1{print $2}'
输出:define.js+common.js=temp/c.js //@1
命令:awk 'NR==1{print $2}' build.config.ini //@2
输出:空
为什么@2 正常输出为空 而@1确不行
标准输出作为数据源在这里面有什么问题吗? 很迷惑
先谢谢了
|
楼主试试 这两种方式print config有什么不同
echo $config
echo "$config"
结果可能比较意外吧,这个结果也可以解释楼主观察到的现象
这个和shell的word splitting或者field splitting有关系,在不带引号的情况下,相当于两个独立的参数, 中间多少个white space并没有关系
好比 ./myProgram a b 和 ./myProgram a b 对于程序myProgram来说没有任何区别
贴上一段man bash供楼主参考
Word Splitting
The shell scans the results of parameter expansion, command substitution, and arithmetic expansion that did not occur within double quotes
for word splitting.
The shell treats each character of IFS as a delimiter, and splits the results of the other expansions into words on these characters. If
IFS is unset, or its value is exactly , the default, then sequences of , , and at the beginning
and end of the results of the previous expansions are ignored, and any sequence of IFS characters not at the beginning or end serves to
delimit words. If IFS has a value other than the default, then sequences of the whitespace characters space and tab are ignored at the
beginning and end of the word, as long as the whitespace character is in the value of IFS (an IFS whitespace character). Any character in
IFS that is not IFS whitespace, along with any adjacent IFS whitespace characters, delimits a field. A sequence of IFS whitespace charac‐
ters is also treated as a delimiter. If the value of IFS is null, no word splitting occurs.
Explicit null arguments ("" or '') are retained. Unquoted implicit null arguments, resulting from the expansion of parameters that have no
values, are removed. If a parameter with no value is expanded within double quotes, a null argument results and is retained.
Note that if no expansion occurs, no splitting is performed.
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。