I am trying to redirect the output to a file within if-else statements but it is not working with me. Here's what I am doing
$1=1
output="/home/file.txt"
if [[ $1 -gt 5 ]]
then
echo "$1 is greater than 5" > $output #this is working with me
else
echo "$1 is not greater than 5" > $output #this is giving me "ambiguous redirect"
fi
Any idea what the issue may be? I tried puting $output between double quotes, but I got a different error message:
if [[ $1 -gt 5 ]]
then
echo "$1 is greater than 5" > "$output" #this is working with me
else
echo "$1 is not greater than 5" > "$output" #this is giving me "No such file or directory"
fi