ShellScript条件分岐ーif文-20100921
ShellScript条件分岐ーif文 - Shammerismのアップデート版。文字列の比較を追加。
#!/bin/bash echo "IF example!"; if [ $# -ne 1 ];then echo "Usage: $0 [123]"; exit 1; fi if [ $1 -eq 1 ];then echo "You are number#1."; elif [ $1 -eq 2 ];then echo "You are number#2."; elif [ $1 -eq 3 ];then echo "You are number#3."; else echo "Invalid argument."; echo "Usage: $0 [123]"; fi if [ $1 = "XYZ" ]; then echo "You type XYZ."; fi if [ $1 != "ABC" ]; then echo "You don't type ABC."; fi exit 0;