whileループの入力を提供する

whileループの入力を提供する
while getopts "f:t:d:g:o:p:b:q:r:" opt; do
    case "$opt" in

(f)fan=${OPTARG}
(t)..
 esac
done
shift $(( OPTIND - 1 ));

入力方法を教えてください。上記のコード スニペットに入力する方法を教えていただけますか?

答え1

この特定のwhileループ( を使用getopts)では、通常はシェルスクリプトそして、オプション/引数を指定してスクリプトを呼び出します。例:

#!/bin/bash

while getopts "f:t:d:g:o:p:b:q:r:" opt; do
  case "$opt" in

  f) fan=${OPTARG}
  ;;
  t) echo "doing somthing with option t = $OPTARG"
  ;;
 esac
done
shift $(( OPTIND - 1 ));

それを実行可能にする

chmod +x yourscript.sh

それを次のように実行します

$ ./yourscript.sh -t 3
doing somthing with option t = 3

関連情報