私はより大きなスクリプトを持っていますが、この小さなスクリプトは問題を示しています:
#!/bin/bash
x=0
if [[ $x == 0 ]]
then
   ls | while read L
   do
     x=5
     echo "this is a file $L and this is now set to five --> $x"
   done
fi
echo "this should NOT be 0 --> $x" 
変数が while ループの外側に設定されている場合、期待どおりに機能します。bash のバージョンは 3.2.25(1)-release (x86_64-redhat-linux-gnu) です。これが明らかなことだとしたら、私はとてもばかげていると感じるでしょう。