1
スクリプトの残りのパラメーターをコマンドに送信したい。例:argから3番目の残りのパラメーターを結合する。
if [ "$2" == "exec" ]; then
other_script execute "$3 $4 $5 $6 $7 (etc etc etc)"
fi
助言してください。
スクリプトの残りのパラメーターをコマンドに送信したい。例:argから3番目の残りのパラメーターを結合する。
if [ "$2" == "exec" ]; then
other_script execute "$3 $4 $5 $6 $7 (etc etc etc)"
fi
助言してください。
一つの方法は、bash
array slice notationを使用することです:
foo() {
echo "[$1]"
echo "[$2]"
echo "[${@:3}]"
}
が生成されますあなたのようにあなたのコードで実装し
$ foo a b c d ef
[a]
[b]
[c d ef]
:あなたが必要な場合は
if [ "$2" == "exec" ]; then
other_script execute "${@:3}"
fi
は、第三に言うと、第4引数では、スライスに長さを適用できます。
other_script execute "${@:3:2}" # :2 is a length specification
別の方法として、あなたはもはや引数$1
または$2
を必要としなかった場合は、だけの方法からそれらをシフトすることである。
foo=${1:?Missing argument one}
bar=${2:-Default}
shift 2
echo "[email protected]" # the first two args are gone, so this is now args #3 on
私はのカップルのために、正直に、この方法を好みます理由:
この素晴らしい答えの詳細が本当に好きです。 – Martlark