【发布时间】:2015-10-27 12:35:01
【问题描述】:
我有一个脚本,其中运行以下命令:
OUTPUT=`echo "User-Name=$username,User-Password=$passwd" | radclient $ip auth $key`
echo $OUTPUT
执行命令后,我在OUTPUT 中得到以下结果。
Received response ID 239, code 2, length = 34
Reply-Message = "Hello, root"
然后我检查OUPUT是否包含“code”:
if grep -wq code <<< $OUTPUT; then
echo "Success"
break;
fi
这也有效。
现在如果我的 OUTPUT 变量包含 code 那么我想提取代码值:2(在上述情况下)
如何实现:
所以输入:
Received response ID 239, code 2, length = 34
Reply-Message = "Hello, root"
输出:2
【问题讨论】: