自分用のメモ。
if
testコマンドと組み合わせる。
testコマンドは[ 1 -eq 1 ]
とも書ける。ただし、空白忘れるとエラーになるので注意。
数値
オプション | 使用例 | 数式 |
---|---|---|
-eq | test num1 -eq num2 | num1=num2 |
-ne | test num1 -ne num2 | num1≠num2 |
-lt | test num1 -lt num2 | num1<num2 |
-le | test num1 -le num2 | num1≦num2 |
-gt | test num1 -gt num2 | num1>num2 |
-ge | test num1 -ge num2 | num1≧num2 |
例) 数値の比較
if test 1 -eq 1; then
echo true
else
echo false
fi
文字列
=
と!=
例) 文字列の比較
if test "hoge" = "hoge"; then
echo true
else
echo false
fi
scp
scp -i ~/.ssh/secret.pem -r user@host:hoge /local/path
秘密key使う時は-i
ディレクトリの時は-r
ああ、以下にいろんな事が詳しく書いてあった。
http://bi.biopapyrus.net/linux/bash.html