- 论坛徽章:
- 5
|
本帖最后由 blackold 于 2014-07-04 10:53 编辑
@lifayi2008
@ly5066113@yestreenstars@yinyuemi
从源码看,确实如 Tim 所言,n 有打印功能。
我的理解是错误的。
主要代码(http://ftp.gnu.org/gnu/sed/sed-4.2.tar.bz2)如下:
sed.c
- /* If set, don't write out the line unless explicitly told to */
- bool no_default_output = false;
- ...
- main (...)
- {
- ...
- # 命令行参数处理
- switch (opt)
- {
- case 'n':
- no_default_output = true;
- break;
- ...
- check_final_program(the_program);
- return_code = process_files(the_program, argv+optind);
- }
复制代码 execute.c
- process_files (...)
- {
- ...
- status = EXIT_SUCCESS;
- while (read_pattern_space(&input, the_program, false))
- {
- status = execute_program(the_program, &input);
- if (status == -1)
- status = EXIT_SUCCESS;
- else
- break;
- }
- closedown(&input);
- ...
- }
- execute_program(...)
- {
- ...
- switch(...)
- # 命令处理
- case 'n':
- if (!no_default_output)
- output_line(line.active, line.length, line.chomped, &output_file);
- if (test_eof(input) || !read_pattern_space(input, vec, false))
- return -1;
- break;
- ...
- case 'q':
- if (!no_default_output)
- output_line(line.active, line.length, line.chomped, &output_file);
- ...
- case 'N':
- str_append(&line, "\n", 1);
-
- if (test_eof(input) || !read_pattern_space(input, vec, true))
- {
- line.length--;
- if (posixicity == POSIXLY_EXTENDED && !no_default_output)
- output_line(line.active, line.length, line.chomped,
- &output_file);
- return -1;
- }
- break;
- ...
- if (!no_default_output)
- output_line(line.active, line.length, line.chomped, &output_file);
- return -1;
- }
复制代码 |
|