bash - How to wrap another shell still passing $OPTIND as-is? -
i'm trying wrap bash script b script a. want pass options passed b are.
#!/bin/bash # script ./b ${@:$optind}
this print $1 (if any). what's simplest way not to?
so calling:
./a -c -d 5 first-arg
i want b execute: ./b -c -d 5 # without first-arg
in bash, can build array containing options, , use array call auxiliary program.
call_b () { typeset -i i=0 typeset -a a; a=() while ((++i <= optind)); # i=1..$optind a+=("${!i}") # append parameter $i $a done ./b "${a[@]}" } call_b "$@"
in posix shell (ash, bash, ksh, zsh under sh or ksh emulation, …), can build list "$1" "$2" …
, use eval
set different positional parameters.
call_b () { i=1 while [ $i -le $optind ]; a="$a \"\$$i\"" i=$(($i+1)) done eval set -- $a ./b "$@" } call_b "$@"
as often, rather easier in zsh.
./b "${(@)@[1,$optind]}"
Comments
Post a Comment