Ambiguous redirect error in shell scripting when creating file name with date
<p>I'm trying to make this temperature log in Raspberry Pi happen (though some of the code did not work therefore I used slightly diff. solutions):</p>

<p><a href="https://www.raspberrypi.org/learning/temperature-log/worksheet/" rel="nofollow">https://www.raspberrypi.org/learning/temperature-log/worksheet/</a></p>

<p>I'm stuck with writing the results in a file. I want to create a file that's name contains the actual date, e.g. temperature_log_2016_08_13.txt</p>

<p>When running the script I get an <em>ambiguous redirection error</em> each time lines with the echo commands execute. I tried all sort of combinations with quotes, double-quotes, no quotes. Pls advice.</p>

<pre><code>#!/bin/bash

timestamp() {
    date +%F_%H-%M-%S
}

temperature() {
    /opt/vc/bin/vcgencmd measure_temp
}

temp=$(temperature)
temp2=${temp:5:9}

echo Temperature Log_$(date) &gt;/home/pi/logs/temperature_log_$(date).txt

for i in {1..5}
do
    echo ${temp2} $(timestamp) &gt;&gt;/home/pi/logs/temperature_log_$(date).txt
    sleep 1
done
</code></pre>

<p>UPDATE: by putting the file name between quotation marks, as advised below, the ambiguous redirect error is gone, but instead the script produces 5 files with the date/timestamp in its name. I need only 1 file into which all the temperatures are written.</p>