
例如:
vrs=123
echo "vrs = $vrs"
# vrs = 123
$(netstat -tlun)指示括号中的内容要做变量替换。
judge.sh内容如下:#!/bin/sh
if [ $# != 1 ]
then echo "usage ./judge.sh var"
exit 1
fi
VAR=$1
temp=`env|awk -F "=" '{printf $1} {printf "\n"}'`
for obj in ${temp}
do
if [ ${VAR} = ${obj} ]
then VAR="Linux C"
echo $1 is an env.
echo and now the value of $1 is ${VAR}.
exit 0
fi
done
echo ${VAR} is not an env.
用法,chmod a+x judge.sh
./judge.sh VAR
当然,如果这个VAR你输入的是真的环境变量的值的话,它是不将值写入配置文件的。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)