shスクリプトで2つの変数を繰り返すには?

shスクリプトで2つの変数を繰り返すには?

カーネル2.6.xの使用

sh(bash、zshなどではない)を使用して、次の変数を使用して以下の結果をどのようにスクリプト化できますか?

VAR1="abc def ghi"
VAR2="1 2 3"
CONFIG="$1"

for i in $VAR1; do
   for j in $VAR2; do
      [ "$i" -eq "$j" ] && continue
   done
command $VAR1 $VAR2
done

望ましい結果:

command abc 1
command def 2
command ghi 3

ベストアンサー1

1つの方法は次のとおりです。

#! /bin/sh

VAR1="abc def ghi"
VAR2="1 2 3"

fun()
{
    set $VAR2
    for i in $VAR1; do
        echo command "$i" "$1"
        shift
    done
}

fun

出力:

command abc 1
command def 2
command ghi 3

おすすめ記事