您的位置:首页 > 运维架构 > Shell

Linux Shell中判断某个环境变量是否存在以及获取某个环境变量的值

2012-02-08 17:14 295 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: