【test5.sh】
``で囲むと変数の出力を変数に代入できる
{}は変数区切り grep -E は正規表現オプション
.t. 任意文字t任意文字で、tを含むファイル抽出
a1=
ls | grep -E ".*t.*"
a1に保存 a2=ls
echo ${a1} echo ${a2} b=pwd
echo "Ima ha ${b} ni imasu"演算コマンド expr
expr 1 + 3
変数を使って計算
n=3 m=
expr ${n} * 5
echo "${m} ha desu"
実行 sh test5.sh test5.sh: 1: grep -E: not found test5.sh: 5: 247032: not found
Ima ha /home/insprings2 ni imasu 4 expr: syntax error: unexpected argument ‘247032’ ha desu
【test6.sh】
test コマンド と if 文
条件をみたすとき、True 条件みたさないときFalse
a="taro"
if test $a == taro
;then
echo "OK"
else
echo "No"
fi
実行 sh test6.sh test6.sh: 4: test $a == taro: not found No
【test7.sh】
test コマンド 条件をみたすとき、
True 条件みたさないときFalse
a="jiro"
if test $a == taro
;then
echo "OK"
else
echo "No"
fi
実行 sh test7.sh test7.sh: 4: test $a == taro: not found No