Bash變量
· 在Bash中,變量的默認(rèn)類型都是字符串型
? ? 如果需要要轉(zhuǎn)換,用declare命令
? ? declare [-aixr] 變量
? ? a: array, i: integer , x:環(huán)境變量, r: readonly只讀變量
變量的“申明和賦值規(guī)則”:變量=值
· 變量的打?。篹cho $變量 或者 echo ${變量}
? ? 把一個(gè)變量的值賦值給另外一個(gè):變量=${變量}

· 變量為可擴(kuò)增變量時(shí):變量="$變量":或者變量=${變量}:
· 調(diào)用額外命令的信息:`指令` 或者? $(指令)

· 若該變量需要在其他子程序中執(zhí)行,需要用export來使變量變成環(huán)境變量
· 取消變量的方法:unset
程序?qū)嵗?/p>
用shell腳本查看主機(jī)是否啟動(dòng)www、ssh、ftp、mail服務(wù)
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
touch?/dev/shm/netstat_check.txt #創(chuàng)建文檔用于存儲(chǔ)信息
netfile=/dev/shm/netstat_check.txt??
netstat -tuln > ${netfile}?#導(dǎo)入命令輸出
testing=$(grep ":80 " ${netstat})# 引用grep的輸出結(jié)果
if [ "${testing}" != "" ]; then
echo "WWW is running in your system."
fi
testing=$
(grep ":22 " ${netstat})#偵測(cè)看port 22在否?
if [ "${testing}" != "" ]; then
echo "SSH is running in your system."
fi
testing=$
(grep ":21 " ${netstat})#偵測(cè)看port 21在否?
if [ "${testing}" != "" ]; then
echo "FTP is running in your system."
fi
testing=$
(grep ":25 " ${netstat})#偵測(cè)看port 25在否?
if [ "${testing}" != "" ]; then
echo "Mail is running in your system."
fi