網上看腳本好多算數計算方法,現統計出來
#!/bin/bash
a=3
b=8
a1=nihao
b1=haode
c=$((a+b))
d=$[$a+$b]
e=`expr $a + $b`
((f=a+b))
c1=$a1$b1 #字符串拼接
echo $c $d $e $f
echo $a1$b1 $c1
[root@instance-k70br3gw shell]# bash gu.sh
11 11 11 11
nihaohaode nihaohaode
c/d/e/f 是三種求和方法
shell是真的隨意
括號的用法:
()聲明數組
array=(1 2 3 40)
(()) 算數運算
[] 算數運算和邏輯運算,不支持&&和||
[[]] 算數運算和邏輯運算,全支持
{}創建匿名函數
在命令行中{}
mkdir /usr/local/jav{a,b,c}
bash +h /腳本 是排錯
bash +x /腳本 是debug
mailx是epel源軟件,需要配置epel倉庫,網上找個源寫到repo配置中去,yum repolist ,然后安裝mailx
[root@instance-k70br3gw local]# yum install mailx -y
[root@instance-k70br3gw local]# rpm -ql mailx
/bin/mail
/bin/mailx
/etc/mail.rc #這是它的配置文件
[root@instance-k70br3gw local]# tail -6 /etc/mail.rc
set bsdcompat
set from=xxxxxx@qq.com
set smtp=smtp.qq.com
set smtp-auth-user=xxxxxx@qq.com
set smtp-auth-password=你的qq郵箱smtp授權碼 #在qq郵箱設置-賬戶里,需要發一個短信驗證
set smtp-auth=login
[root@instance-k70br3gw local]# echo "這是來自本地的測試郵件" | mail -s "辦公室老板收" xxxxx@qq.com
上述步驟做完,幾秒鐘郵件就到了
shell腳本實現郵件功能
#!/bin/bash
#
js () {
read -p "請輸入郵件標題:" tile
read -p "請輸入收件人:" who
if [[ ! -n "$tile" ]] && [[ ! -n "$who" ]]
then
echo "您的輸入有誤,請重新輸入"
js
else
read -p "請輸入要導入的正文文件名,文件請放在/var/mail/下并以.mail結尾" file
if [ -f "/var/mail/$file" ]
then
file=`cat /var/mail/$file`
echo "你的正文是: $file"
echo $file | mail -s $tile $who && echo "郵件已發送"
else
echo "文件名不對,請確認"
sleep 0.2
exit 12
fi
}
js
fi[root@instance-k70br3gw shell]# bash mail.sh
請輸入郵件標題:X總中午好
請輸入收件人:xxxxxxx@qq.com
請輸入要導入的正文文件名,文件請放在/var/mail/下并以.mail結尾send.mail
你的正文是: 你好
郵件已發送