我想設置一個變量的基礎上,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