我需要运行一个命令:
python test.py command --option 1 value1 value2 value3 value4 value5
Run Code Online (Sandbox Code Playgroud)
(最多值100)
我有一个带有空格分隔值的文本文件,例如:
值1 值2 值3 值4 值5 ..
如何将其通过管道传输到命令中,而不将整个文件内容复制并粘贴到终端中?
您可以使用 Bash 命令替换功能:
python test.py command --option 1 $(<file.txt)
Run Code Online (Sandbox Code Playgroud)
从man bash
:
Command substitution allows the output of a command to replace
the command name. There are two forms:
$(command)
or
`command`
Bash performs the expansion by executing command and replacing
the command substitution with the standard output of the command,
with any trailing newlines deleted. Embedded newlines are not
deleted, but they may be removed during word splitting. The
command substitution $(cat file) can be replaced by the
equivalent but faster $(< file).
Run Code Online (Sandbox Code Playgroud)