![whileループの入力を提供する](https://rvso.com/image/1047577/while%E3%83%AB%E3%83%BC%E3%83%97%E3%81%AE%E5%85%A5%E5%8A%9B%E3%82%92%E6%8F%90%E4%BE%9B%E3%81%99%E3%82%8B.png)
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