[ ] [ トップページ ] [ 目次 ] [ コマンド行入力編集 ] [ 展開/置換 ] [ リディレクション ] [ 制御構造 ] [ 式と演算 ] [ 組込みコマンド ] [ ヒストリ ] [ ジョブ制御 ] [ シェル変数 ] [ setコマンド ] [ その他 ]  

条件式の使用例

スクリプト/コマンド入力       
実行結果
Bシェル(bsh)スタイルの条件式
n=10
if [ $n = 10 ]; then
	echo "\$n is 10";
else
	echo "\$n is not 10";
fi
$n is 10
n=100
if [ $n = 10 ]; then
	echo "\$n is 10";
else
	echo "\$n is not 10";
fi
$n is not 10
n=100
if [ ! $n = 10 ]; then
	echo "\$n is not 10";
else
	echo "\$n is 10"; 
fi
$n is not 10
n=10
nn=100
if [ $n = 10 -a $nn = 100 ]; then
	echo "\$n is 10 and $nn is 100"
else
	echo "\$n is not 10 or $nn is not 100"
fi
$n is 10 and $nn is 100
n=10
if [ $n ]; then
	echo "\$n is not null"
else
	echo "\$n is null"
fi
$n is not null
Bashの条件式
if [ -f thefile ]; then
	echo "thefile exists!";
else
	echo "no thefile!";
fi
thefile exists!
 

  
WB00806_.gif (471 バイト)
Copyright(C) 1997-1999 GlassCom
webmaster@glasscom.com