# 条件式
if [ cond1 ]; then
# 処理1
elif [ cond2 ]; then
# 処理2
else
# 処理3
fi
# 結合
# &&
if [ cond1 -a cond2 ]; then
fi
# ||
if [ cond1 -o cond2 ]; then
fi
# !
if [ ! cond1 ]; then
fi
# 数値比較
num1 -eq num2 # =
num1 -lt num2 # <
num1 -ne num2 # !=
num1 -le num2 # <=
num1 -ge num2 # >=
num1 -gt num2 # >
# 文字列比較
$1 = $2
$1 != $2
$1 < $2
-n $1 : is not null
-z $1 : is zero
# file
-d : directory
-b : binary
-e : exist
-r : readable
-o : owner
-G : group
-g : set gid bit
-L : symboliclink
file1 -nt file2 : new then (modifytime)
file1 -ot file2 : old then (modifytime)
# case
case 変数 in
パターン1) 処理;;
パターン2) 処理;;
パターン3 | パターン4) 処理;;
*) 処理;;
esac
# Loop
# while
a=0
while [ $a -ne 10 ]
do
a=`expr $a + 1`
echo "${a} 回目の処理"
done
while read line
do
処理(${line}を処理)
done < ファイル
# for
for i in 1 2 3;
do
echo $i
done
# array
array=(`ls ./`);
array+=(elm1 elm2); # 追加
echo ${array[@]}; #全リストを表示
echo ${array[1]}; #2番目の要素を表示
for i in "${array[@]}";
do
echo $i
done
echo "{#array[@]}"; # 要素数を参照
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme