使用一个命令的输出作为另一个命令的参数
Using the output of one command as the argument for another
我正在尝试 grep 文件并将行号通过管道输出到
vim +{lineNumber} filetoedit
不幸的是 Vim 抛出一个错误说
Vim: Warning: Input is not from a terminal
一个例子:
grep -nF 'Im looking for this' testfile.txt | cut -f1 -d: | xargs vim +{} testfile.tx
xargs
的命令 运行 从 xargs
继承了 stdin
,因此它的输入连接到来自 cut
的管道,而不是终端。
将结果分配给一个变量并使用它。
line=$(grep -nF 'Im looking for this' testfile.txt | cut -f1 -d: )
vim "+$line" testfile.txt
我正在尝试 grep 文件并将行号通过管道输出到
vim +{lineNumber} filetoedit
不幸的是 Vim 抛出一个错误说
Vim: Warning: Input is not from a terminal
一个例子:
grep -nF 'Im looking for this' testfile.txt | cut -f1 -d: | xargs vim +{} testfile.tx
xargs
的命令 运行 从 xargs
继承了 stdin
,因此它的输入连接到来自 cut
的管道,而不是终端。
将结果分配给一个变量并使用它。
line=$(grep -nF 'Im looking for this' testfile.txt | cut -f1 -d: )
vim "+$line" testfile.txt