我需要为进一步的参考定义一个全局变量
这是我的代码
# .bashrc
LOCAL_CONF_DIR='/var/www/vhosts/vhost/test.conf'
cat ${LOCAL_CONF_DIR} | while read LINE
do
if [ "ServerName" == "${LINE:0:10}" ]; then
s=( $LINE )
SERVER_NAME=$s[1];
fi
done
echo $SERVER_NAME
对我来说不起作用RHE Linux 6.0
非常感谢;)
答案 0 :(得分:3)
您的if syntax
不正确,您的循环不应该使用cat
。使用此代码:
SERVER_NAME=""
while read -r LINE
do
if [ "${LINE:0:10}" = "ServerName" ]; then
SERVER_NAME="${LINE:10}"
fi
done < "${LOCAL_CONF_DIR}"
echo "$SERVER_NAME"