0

助けてくれてありがとう!!!

私は次のコードを持っています:

base[0]='coordfinder'
base[1]='editor_and_options'
base[2]='global'
base[3]='gyro'
base[4]='movecamera'
base[5]='orientation'
base[6]='sa'

for d in $dest_include/*; do
    if [ $d == "${base[@]}" ]; then
        echo $plugin='y' >> vt_conf.sh
    else
        plugin=$(basename $d)
        echo $plugin'?'
        read $plugin
        echo $plugin=${!plugin} >> vt_conf.sh
    fi
done

それは機能しませんが、それは良い出発点です。基本的に機能しないのはifループです。やり方がわからないので作りました。

私は次のことをしたいです:

$dest_includeフォルダーのコンテンツをループします。いずれかのフォルダー($ d)が配列内の要素のいずれかに一致する場合は、1つのことを実行し、それ以外の場合は別のことを実行します。

ありがとう!!!

4

2 に答える 2

1

内側のループを反復処理し、一致が見つかった場合はフラグを設定します。

base=( coordfinder editor_and_options global gyro movecamera orientation sa )
for d in "$dest_include/"*; do
  found_match=0
  for i in "${base[@]}"; do
    [[ $d = "$i" ]] && { found_match=1; break; }
  done
  if (( found_match )) ; then
    ...do one thing...
  else
    ...do the other...
  fi
done
于 2012-10-26T12:44:43.280 に答える
0

チェックを逆にすることもできます。配列全体を空白で区切られた文字列として使用し、その中の空白で区切られた単語と一致させようとします。

for d in "$dest_include"/* do
    if [[ " ${base[*]} " == *" $(basename "$d") "* ]]; then
        do something with matching directory
    else
        do another thiing
    fi
done
于 2012-10-26T14:42:12.527 に答える