标签:shell
参考:
http://bbs.chinaunix.net/thread-1633281-1-1.html
需求:
判断变量cache_dir中是够包括"/data/cache"字符串
法1:
if [[ "${cache_dir}" =~ "/data/cache" ]]; then
echo "true"
fi法2:
if [[ ${cache_dir} = */data/cache* ]]; then
echo "true"
fi法3:
if echo ${cache_dir} |grep -q "/data/cache"; then
echo "true"
fi法4:
echo ${cache_dir} |grep -q "/data/cache" && echo "true" || echo "false"特别说明,以上方法适用于所有遵从POSIX的shell,如ksh。
标签:shell
原文地址:http://xoyabc.blog.51cto.com/7401264/1833778