怎么把switch case中的局部变量在 整个shell脚本使用? 10
#解析conf参数conf=user.confcat$conf|whilereadfiledokey=`echo$file|awk-F":"'{print$1}'`;va...
#解析conf参数
conf=user.conf
cat $conf | while read file
do
key=`echo $file |awk -F":" '{print $1}'`;
val=`echo $file |awk -F":" '{print $2}'`;
if [[ ${key:0:1} != "#" ]]
then
case "$key" in
"user_path" )
user_path=$val
export user_path
echo "user_path is $val";;
"user_port" )
odp_port=$val;
echo "user_port is $val";;
esac
fi
done
echo $user_path
怎么得到user_path是 /home/user/abc,现在输出是空的
user.conf
user_path: /home/user/abc
user_port: 8080 展开
conf=user.conf
cat $conf | while read file
do
key=`echo $file |awk -F":" '{print $1}'`;
val=`echo $file |awk -F":" '{print $2}'`;
if [[ ${key:0:1} != "#" ]]
then
case "$key" in
"user_path" )
user_path=$val
export user_path
echo "user_path is $val";;
"user_port" )
odp_port=$val;
echo "user_port is $val";;
esac
fi
done
echo $user_path
怎么得到user_path是 /home/user/abc,现在输出是空的
user.conf
user_path: /home/user/abc
user_port: 8080 展开
展开全部
你把该变量在脚本开始时声明一下试试,我也是shell新手,而且这里没装环境没有验证,你验证一下把脚本改成下面的样子:
#解析conf参数
user_path = “”
conf=user.conf
cat $conf | while read file
do
key=`echo $file |awk -F":" '{print $1}'`;
val=`echo $file |awk -F":" '{print $2}'`;
if [[ ${key:0:1} != "#" ]]
then
case "$key" in
"user_path" )
user_path=$val
export user_path
echo "user_path is $val";;
"user_port" )
odp_port=$val;
echo "user_port is $val";;
esac
fi
done
echo $user_path
#解析conf参数
user_path = “”
conf=user.conf
cat $conf | while read file
do
key=`echo $file |awk -F":" '{print $1}'`;
val=`echo $file |awk -F":" '{print $2}'`;
if [[ ${key:0:1} != "#" ]]
then
case "$key" in
"user_path" )
user_path=$val
export user_path
echo "user_path is $val";;
"user_port" )
odp_port=$val;
echo "user_port is $val";;
esac
fi
done
echo $user_path
来自:求助得到的回答
展开全部
可以在头部声明下试试看,
在
conf=user.conf
前面加
user_path=
在
conf=user.conf
前面加
user_path=
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我在电脑是试是能行的啊,代码也没有问题输出为
user_path is /home/user/abc
user_port is 8080
user_path is /home/user/abc
user_port is 8080
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询