Bash 打印n行a";命令';s--帮助“;关于stdout
这只是一个我还没有解决的好奇心(尝试sed、awk、tail、head等) 这项工作:Bash 打印n行a";命令';s--帮助“;关于stdout,bash,shell,stdout,Bash,Shell,Stdout,这只是一个我还没有解决的好奇心(尝试sed、awk、tail、head等) 这项工作: $ ls --help | head -n 2 Usage: ls [OPTION]... [FILE]... List information about the FILEs (the current directory by default). 为什么与其他命令不起作用 $ tree --help | head -n 2 Prints the whole --help! not just the fi
$ ls --help | head -n 2
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
为什么与其他命令不起作用
$ tree --help | head -n 2
Prints the whole --help! not just the first 2 lines!
tree
(和一些其他命令)将其帮助打印到stderr,而不是stdout。您只需使用|&
而不是|
来重定向这两个文件:
tree --help |& head -n2
或者对4以上的bash版本使用树--help 2>&1 | head-n2
(或类似版本)(我相信这就是添加&
的地方)。