[英]Recombine bash arguments when using pipeline
What approach can be used in case of recombine bash arguments, for example: 在重组bash参数的情况下可以使用什么方法,例如:
echo "arg3 arg1 arg2" | ...
so as recombine arguments in random sort can be applicable: 因此可以采用随机排序的重组参数:
... | some_command -arg1=$3 -arg2=$1 -arg3=$2 --interpretator-arg=$0 --anoter-arg=$1$2$3
One option would be to use read
: 一种选择是使用read
:
echo "arg3 arg1 arg2" | { read -r a b c; some_command ...; }
Now you can use arguments "$a"
, "$b"
and "$c"
as you wish. 现在,您可以根据需要使用参数"$a"
, "$b"
和"$c"
。
I guess your example is a bit artificial but you can avoid a pipeline in this case: 我想您的示例有点人为,但在这种情况下可以避免使用管道:
{ read -r a b c; some_command ...; } <<< "arg3 arg1 arg2"
If the arguments really come from a command, then you can use a command substitution: 如果参数确实来自命令,则可以使用命令替换:
{ read -r a b c; some_command ...; } < <(command_producing_arguments)
Note that the semicolon at the end is important, if the command group { }
is written all on one line. 请注意,如果命令组{ }
全部写在一行上,则末尾的分号很重要。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.