練習 寫一個腳本
能接受一個參數(文件路徑);判定:此參數如果是一個存在的文件,就顯示“OK”;否則就顯示“No such the file.”
[root@localhost mscripts]# cat lx7.sh
#!/bin/bash
if [ $# -lt 1 ]; then
echo "please input argument."
exit 9
fi
if [ -f $1 ]; then
echo "ok"
else
echo "No such file."
fi
練習 2 寫一個腳本
給腳本傳遞兩個參數(整數);顯示此兩者之和,之積;
[root@localhost mscripts]# cat lx8.sh
#!/bin/bash
if [ $# -lt 2 ]; then
echo "please input two digit."
exit 9
fi
echo -e "Sum is $[$1+$2].\nproduct is $(($1*$2))."