Q:

Shellscript with ambiguous redirect error

My shellscript is not working:
#!/bin/bash
LIST="$(ls -rt *.log.*)"

for i in "$LIST"; do

echo $i

mysql --user=<user> --password=<passwd> <database> < $i

done

result: ./analisys.sh: line 5: $i: ambiguous redirect
Can you help me?

A:

You shouldn't expand $LIST if you want to operate on each whitespace separated item. I.e remove the two ". You don't need them in the first occurrance either.
This should have been apparent when you listed the items with echo $i, I suspect all files where listed at once, and not each at a time.
#!/bin/bash
LIST=$(ls -rt *.log.*) # THIS LINE CHANGED

for i in $LIST; do # THIS LINE CHANGED

    echo $i
    mysql --user=<user> --password=<passwd> <database> < $i

done

