-------------------------------------------------------------------------------------------
set:查看本地变量
env:查看环境变量
alias:查看已经定义的别名
-------------------------------------------------------------------------------------------
JDK的检查:
if [ "x$JAVAHOME" = "x" ]; then
echo "JAVAHOME环境变量未设置"
exit 1
fi
if [ -x $JAVAHOME/bin/java ]; then
printf ""
else
echo "错误的JAVAHOME环境变量设置。$JAVAHOME/bin/java 程序不存在。"
echo "请重新指定JDK安装路径。"
exit 2
fi
if [ -x $JAVAHOME/bin/javac ]; then
printf ""
else
echo "您指定的JAVAHOME环境变量为$JAVAHOME"
echo "该位置下找不到javac命令。可能您安装的是JRE而不是JDK。请检查。"
exit 6
fi
R="`$JAVAHOME/bin/java -version 2>&1`"
if [ "x`echo $R | grep 'Could not reserve enough space for object heap'`" != "x" ]; then
echo "$JAVAHOME/bin/java运行出错:内存不足无法启动。请检查系统资源占用情况。"
echo $R
exit 3
fi
if [ "x`echo $R | grep Error`" != "x" ]; then
echo "$JAVAHOME/bin/java运行出错。请检查。"
echo $R
exit 4
fi
if [ "x`echo $R | grep '\"1\.5'`" = "x" ]; then
echo "$JAVAHOME/bin/java 的版本不是1.5。"
echo "请设置环境变量JAVAHOME指向正确版本的JDK安装路径。"
exit 5
fi
cd "`/usr/bin/dirname $0`/.."
if [ "x$MMS_HOME" = "x" ]; then
MMS_HOME=`/bin/pwd`
export MMS_HOME
fi
cd $MMS_HOME
MMS_HOME=`/bin/pwd`
CLASSPATH=`ls -1 $WADHOME/bin/*.jar |/usr/bin/tr '\n' ':'`; export CLASSPATH
}
-------------------------------------------------------------------------------------------
readonly:
定义的变量是只读的,相当于final
#!/bin/bash
readonly name=xuxu
echo $name
name=xuxux
echo $name
但要注意:
typeset readonly name=xuxu时,这时的readonly会失效!
-------------------------------------------------------------------------------------------
#转到上层目录
cd `dirname $0`/..
-------------------------------------------------------------------------------------------
比较运算:
#!/bin/bash
#可以比较数字
if [[ 1 <= 2 ]];then
echo 'ok'
fi
#也可以比较字符串
if [[ "a" < "b" ]];then
echo 'ok'
fi
#下面这两种方式不要使用
#!/bin/bash
if [ 1 ] ; then
echo 'oookkkk'
fi
if [ true ]; then
echo 'ook'
fi
//另一种比较的写法,据点是:只能比较整数
#!/bin/bash
a=1
b=2
//当然也可以((a<=b))
if (($a<=$b));then
echo 'ok'
fi
-------------------------------------------------------------------------------------------