1.取变量或字符串长度的方法:
1)echo $a|wc -L
2)echo ${#a}
3)expr length $a
*************************************************************************************
*************************************************************************************
脚本:
*************************************************************************************
check_url:
#!/bin/bash
[ -f /etc/init.d/functions ]&& ./etc/init.d/functions
usage(){
echo "USAGE:$0 url"
exit 1
}
RETVAL=0
checkurl(){
wget -T 10 --spider -t 2 $1 &>/dev/null
RETVAL=$?
if[ $RETVAL -eq 0 ];then
action "$1 url" /bin/true
else
action "$1 url" /bin/false
fi
return $RETVAL
}
main(){
if [ $# -ne 1 ];then
usage
fi
checkurl $1
RETVAL=$?
return $RETVAL
}
main $*
*************************************************************************************
menu:
#制作菜单脚本,要求:执行脚本时显示选择菜单,当选择相应数字后执行相关操作。
menu(){
cat << EOF
++++++++++++++++++++
+ 1.install lamp +
+ 2.install lnmp +
+ 3. exit +
++++++++++++++++++++
EOF
echo -e "\e[1;31m INPUT THE NUM YOU WANT: \e[0m"
}
menu
read num
[ "$num" -eq "1" ]&&{
echo "start installing lamp"
[ -x /server/scripts/lamp.sh ]||{
echo "lamp.sh is error."
exit 2
}
/server/scripts/lamp.sh
exit 0
}
[ "$num" -eq "2" ]&&{
echo "start installing lnmp"
[ -x /server/scripts/lnmp.sh]||exit 2
/server/scripts/lnmp.sh
exit 0
}
[ "$num" -eq "3" ]&&{
echo "bye"
exit 0
}
echo "Input Error"
exit 1
*************************************************************************************
*************************************************************************************
*************************************************************************************
*************************************************************************************