Just use an unquoted command substitution:
$ ./command2 $(./command1)
However, this also subjects the output of command1
to pathname generation, so if the output could include something like *.txt
, you risk that being expanded to multiple words before being passed to command2
. In that case, you'll need to use
$ read arg1 arg2 arg3 <<< "$(./command1)"
$ ./command2 "$arg1" "$arg2" "$arg3"
or
$ read -a args <<< "$(./command1)"
$ ./command2 "${args[@]}"
to split the output into 3 words without subjecting them to pathname generation.
This won't work if the output of command1
looks like
"word1a word1b" word2
and you expect to be able to pass two arguments, word1a word1b
and word2
to command2
, but getting that right is sufficiently tricky to require more details about what command1
could output to provide the correct solution.