Shell script result output to a file
<p>I just faced a problem about shell script output problem. Here is the code</p>

<pre><code>read_each_user_rating(){
TOTAL_RATING_NUMBER="$(grep -c '&lt;Author&gt;' $1)" #Find how many rating in each file
ALL_AUTHOR="$(grep '&lt;Author&gt;' $1 | sed -e 's/&lt;Author&gt;//'| tr -d '\r')"
ALL_COMMENT="$(grep '&lt;Content&gt;' $1 | sed -e 's/&lt;Content&gt;//'| tr -d '\r')"
ALL_DATE="$(grep '&lt;Date&gt;' $1 | sed -e 's/&lt;Date&gt;//'| tr -d '\r')"
ALL_RATING_FILE="$(grep '&lt;Overall&gt;' $1 | sed -e 's/&lt;Overall&gt;//'| tr -d '\r')"
ALL_VALUE="$(grep '&lt;Value&gt;' $1 | sed -e 's/&lt;Value&gt;//'| tr -d '\r')"
ALL_ROOMS="$(grep '&lt;Rooms&gt;' $1 | sed -e 's/&lt;Rooms&gt;//'| tr -d '\r')"
ALL_LOCATION="$(grep '&lt;Location&gt;' $1 | sed -e 's/&lt;Location&gt;//'| tr -d '\r')"
ALL_CLEANLINESS="$(grep '&lt;Cleanliness&gt;' $1 | sed -e 's/&lt;Cleanliness&gt;//'| tr -d '\r')"
ALL_CHECKIN="$(grep '&lt;Check in / front desk&gt;' $1 | sed -e 's/&lt;Check in / front desk&gt;//'| tr -d '\r')"
ALL_SERVICE="$(grep '&lt;Service&gt;' $1 | sed -e 's/&lt;Service&gt;//'| tr -d '\r')"
ALL_BUSSINESS="$(grep '&lt;Bussiness service&gt;' $1 | sed -e 's/&lt;Bussiness service&gt;//'| tr -d '\r')"
for ((COUNTER_A=1;COUNTER_A&lt;=$TOTAL_RATING_NUMBER;COUNTER_A++))
do
echo "INSERT INTO UserRating (Author,Comment,Date,Overall,Value,Rooms,Locations,Cleanliness,Checkin,Service,Bussiness)" &gt;&gt; hotelreviews.sql
echo $($ALL_AUTHOR | sed "${COUNTER_A}q;d") &gt;&gt; hotelreviews.sql
done
}
read_each_user_rating $1
</code></pre>

<p>I can output
     echo "INSERT INTO UserRating (Author,Comment,Date,Overall,Value,Rooms,Locations,Cleanliness,Checkin,Service,Bussiness)" >> hotelreviews.sql to the file. But why i can output "echo $($ALL_AUTHOR | sed "${COUNTER_A}q;d") >> hotelreviews.sql" part to file too?</p>