我想设置一个变量的基础上,MySQL的声明是这样的执行结果:无法获取管道内设置shell变量的准确值
errorOut=0
mysql -uroot -pinsite3 -rN --execute "select file_system_id from ifm.PartitionTable where physical_partition='$partName'" | while read myVal
do
echo "myVal = $myVal"
if [ $myVal -eq $fsId ];then
errorOut=1
echo "Found equal: errorOut = $errorOut"
fi
done
echo "Outside loop: errOut = $errorOut"
Here is the output:
myVal = 1
myVal = 2
Found equal: errorOut = 1
Outside loop: errOut = 0
正如你所看到的,由于管道我无法获得循环外的变量的值(因为管道内的变量,基本上设置分叉不同的过程)
有没有什么办法可以提取循环外的实际值?
谢谢...好:) – kingsmasher1
我很高兴它帮助:) – Yannoff