Bash behaving differently
Hello,
This is strange and I have no clue why: On my desktop system (opensuse 11) the following script runs without an issue on bash 3.2.39 echo " " >> $ilog echo "==> Copying $apps directory " >> $ilog let "ix=0" while [ "$ix" -lt 5 ] do rsync $opt $apps $rserver$m_bkps 1>> $ilog 2>> $elog rc=$? if [[ $rc -gt 0 ]]; then let "ix+=1" else let "ix=5" fi done if [[ $rc -gt 0 ]]; then echo " " >> $elog echo ">>> Error copying dir: $apps. rc=$rc <<<" >> $elog exit 1 fi On my server (ubuntu 8.04) the same script fails. Bash 3.2.39 It complains about "let" and "[[". I had to change it to this: date >> $ilog echo " " >> $ilog echo "==> Copying $srcdir directory " >> $ilog ix=0 while [ $ix -lt 3 ] do rsync $opt * $trgdir 1>> $ilog 2>> $elog rc=$? if [[ $rc -gt 0 ]]; then ix=$(($ix+1)) else ix=3 fi done if [ $rc -gt 0 ]; then echo " " >> $elog echo ">>> copy dir failed: $srcdir. rc=$rc <<<" >>$elog exit 1 fi I had to change let to use $(()) and [[ to [ WHY ? |
I bet your script has "#!/bin/sh" at the top. On the ubuntu system change it to "#!/bin/bash".
Ubuntu 8.04 and some earlier versions link /bin/sh to dash rather than bash, though bash is used for login and interactive shells. The ubuntu developers say that dash executes faster than bash and saves some time at bootup. I ran into similar problems when I upgraded from ubuntu 6.06, which still used bash for everything, to 8.04, and it had me really confused for a while too. |
That's exactly right. I would have spent hours trying to figure this one out, and end up frustrated.
Thanks for the info and for averting countless hours of frustration. |
All times are GMT -5. The time now is 10:54 AM. |