Shell中判断某个环境变量是否存在以及获取某个环境变量的值
#!/bin/bash
if [ $TOMCAT_HOME ];
then
echo "not found "
else
tar xvf /home/a.tar
fi
echo $TMPPATH #直接用'#'+环境变量名在shell中使用环境变量的值
if [ -z $TMPPATH ] ; then
echo "no tmppath "
else
...
fi
-z 是检查字符串是否为空
检查文件为空用 -s来判断
-a file True if file exists.
-d file True if file exists and is a directory.
-f file True if file exists and is a regular file.
-n string True if the length of string is non-zero.
string1 == string2 True if the strings are equal.
string1 != string2 True if the strings are not equal.
string1 < string2 True if string1 sorts before string2 lexicographi
简单明了的shell bash脚本文件生成介绍: http://blog.sina.com.cn/s/blog_633fdd420100pnt4.html