分类: 系统运维
2013-05-27 11:09:13
kloxo:
if [ "$#" == 0 ] ; then echo echo " -------------------------------------------------------------------------" echo " format: sh $0 --type=$# 获得参数的个数[--version=version]" echo " -------------------------------------------------------------------------" echo echo " --type - compulsory, please choose between master or slave " echo " depending which you want to install" echo " --version - optional; default: 'current', or any version number as " echo " listed in the archive (between 'kloxo-' and '. zip')" echo " An archive is available at ''" echo echo " We need additional files when installing 6.0.x version:" echo " 1. all additional files must be in the same place of 'kloxo-installer.sh'" echo " 2. download kloxo from archive and then change 'version' to 'current'" echo " 3. check thirdpartyfrom:" ; echo " ''" echo " 4. download thirdparty from:" echo " ''" echo " 5. rename kloxo-thirdparty..zip to kloxo-thirdparty.2012.zip" echo exit; fi
var=”teststring” newvar=”Value of var is $var” echo $newvar结果
Value of var is teststring
APP_NAME=Kloxo request1=$1 APP_TYPE=${request1#--type\=} if [ ! $APP_TYPE == 'master' ] && [ ! $APP_TYPE == 'slave' ] ; then echo "Wrong --type= entry..." exit; fi$1 为命令行的第一个参数,固定为 --type=master/slave
字符串比较if [ condition-true ] then command 1 command 2 ... else # 或选的(如果不需要就可去掉). # 如果条件测试失败,就在这里加入默认的执行命令. command 3 command 4 ... fi
[[ $a == z* ]] # 如果变量$a以字符"z"开始(模式匹配)则为真. [[ $a == "z*" ]] # 如果变量$a与z*(字面上的匹配)相等则为真. [ $a == z* ] # 文件扩展和单元分割有效. [ "$a" == "z*" ] # 如果变量$a与z*(字面上的匹配)相等则为真.
# 多谢Stéphane Chazelas
request2=$2 DB_ROOTPWD=${request2#--db-rootpassword\=} SELINUX_CHECK=/usr/sbin/selinuxenabled SELINUX_CFG=/etc/selinux/config ARCH_CHECK=$(eval uname -m) E_SELINUX=50 E_ARCH=51 E_NOYUM=52 E_NOSUPPORT=53 E_HASDB=54 E_REBOOT=55 E_NOTROOT=85 C_OK='\E[47;34m'"\033[1m OK \033[0m\n" C_NO='\E[47;31m'"\033[1m NO \033[0m\n" C_MISS='\E[47;33m'"\033[1m UNDETERMINED \033[0m\n"selinuxenabled
evaloutput=$(sed -n /"$1"/p $file) # 来自于 "grp.sh"例子.
# 将一个文本的内容保存到变量中.
File_contents1=$(cat $file1)
File_contents2=$(<$file2) # Bash 也允许这么做.
整数比较#!/bin/bash ARGS=3 # 脚本要求三个参数. E_BADARGS=65 # 传递了错误的参数个数给脚本. if [ $# -ne "$ARGS" ] # 测试脚本参数的个数 then echo "Usage: `basename $0` old-pattern new-pattern filename" exit $E_BADARGS fi
在管道中,一次运行几个命令。从管道返回的状态码是最后一个命令的状态码。printf "%d\n" "$?"
ls badfile.txt | wc -l
ls: badfile.txt: No such file or directory
printf "%d\n" "$?" 0 printf "%d %d\n" "${PIPESTATUS[0]}" "${PIPESTATUS[1]}" 1 0
参数:C_OK='\E[47;34m'"\033[1m OK \033[0m\n" echo -en "Installing as \"root\" " $C_OK
# Check if user is root. if [ "$UID" -ne "0" ] ; then echo -en "Installing as \"root\" " $C_NO echo -e "\a\nYou must be \"root\" to install $APP_NAME.\n\nAborting ...\n" exit $E_NOTROOT else echo -en "Installing as \"root\" " $C_OK fi内建变量