0

What approach can be used in case of recombine bash arguments, for example:

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
Dmitry Dubovitsky
  • 2,186
  • 1
  • 16
  • 24

1 Answers1

1

One option would be to use read:

echo "arg3 arg1 arg2" | { read -r a b c; some_command ...; }

Now you can use arguments "$a", "$b" and "$c" as you wish.

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.

Tom Fenech
  • 72,334
  • 12
  • 107
  • 141