Once I decided weirdly to combine two commands into a single one with possibility to keep the command line options of the both commands. It was assumed the following:
# original and simple usage
command1 options1 | command2 options2
# modified and weird one
super_command options1 -- options2
Bash supports string and array indexing, whereas a POSIX shell does not. With bash we can use something similar to (assuming that the double dash "--" is on the sixth position):
command1 "${@:1:5}" | command2 "${@:7}"
I found a workaround way for POSIX. It has been tested under BusyBox which provides the restricted and POSIX-compliant ash
.
Usage (see the complete proof of the concept below)
minus_minus_position "$@"
eval log_left $( reparse_left_arguments "$@" ) \
| eval log_right $( reparse_right_arguments "$@" )