LoginSignup
13
14

More than 5 years have passed since last update.

shell scriptで対話式で処理を進めるメモ

Posted at
#!/bin/sh

while read -p "Do you want to move the www directory?[y/n] " yn ; do
    case $yn in
        [Yy]* ) {
            echo ----------------------
            echo "       MOVING"
            echo ----------------------
            mv www www2
            mv www2/build/production www
            rm -dR www2/build www2/archive
            exit
        };;
        [Nn]* ) exit;;
        * ) echo "Please answer yes or no.";;
    esac

done

read [変数名]
で標準入力からの入力を変数に格納する。

case文は、各パターンを完全一致か部分一致(正規表現)で記述する。

case [変数] in
    パターン1) ;; #処理1
    パターン2) ;; #処理2
    * ) ;; #なにも入力されなかったとき
esac
13
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
14