在我运行我输入的脚本之前
# export CPIC_MAX_CONV=500
Run Code Online (Sandbox Code Playgroud)
以下是test1.script文件
#!/bin/bash
function cpic () {
var="`export | grep -i "CPIC_MAX_CONV" | awk '/CPIC_MAX_CONV/ { print $NF } '`"
[[ $var=="" ]] && (echo "Empty String <<")
[[ $var!="" ]] && (echo "$CPIC_MAX_CONV")
echo "$var" ;
}
cpic
Run Code Online (Sandbox Code Playgroud)
输出是:
# test1.script ---- Me running the file
Empty String <<
500
CPIC_MAX_CONV="500"
Run Code Online (Sandbox Code Playgroud)
无论我使用什么""或""或[或[结果是相同的.该CPIC_MAX_CONV变量由上述脚本找到.
我在Linux/CentOS 6.3上运行它.
这个想法很简单:找到是否CPIC_MAX_CONV在环境中定义并返回它的值.如果有空的空间,那么当然系统中不存在变量.