- 论坛徽章:
- 2
|
本帖最后由 yinyuemi 于 2014-07-03 18:07 编辑
@ly5066113@blackold
恶补了下sed
下载了sed-4.2.2的source code看了看, 附件中把后缀tar改成c
sed.c
case 'n':
no_default_output = true; # 当设置-n参数时,no_default_output 为true, 这个很重要,用于execut.c中命令 n 的执行控制,如下面的引用
break;
execute.c
case 'n':
if (!no_default_output) # 如果-n设置,此条件为假,不执行,这也就是为什么sed -n n,没有输出的原因
output_line(line.active, line.length, line.chomped, &output_file);
if (test_eof(input) || !read_pattern_space(input, vec, false))
return -1;
break;
case 'p':
output_line(line.active, line.length, line.chomped, &output_file); # 注意 命令p是不受no_default_output控制的
break;
if (!no_default_output) # 此处为全局的判断,即所有命令执行结束之后(t,b等有branch功能的命令除外),判断是否执行print,即auto-print功能
output_line(line.active, line.length, line.chomped, &output_file);
return -1;
这样看来,n还是有print功能的,并且受到参数-n的控制
|
|