Search code examples
bashshellcygwin

$INPUT Ambiguous redirect


I wrote this script a while ago and it worked fine, but for some reason I am getting a "Ambiguous redirect" error message for line 11 in cygwin now.

#!/bin/bash
cd 'my/file/path'
INPUT= ./Students.csv
OLDIFS=$IFS
IFS=,
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
while read flname
do
    cp Rubric.pdf ./Grades/$flname_rubric.PDF

done < $INPUT
IFS=$OLDIFS

What am I doing wrong here?


Solution

  • As already noted remove the space. so line reads INPUT=./Students.csv

    Wrap the $INPUT in "" so it reads done < "$INPUT"

    I added echo "cp Rubric.pdf ./Grades/$flname_rubric.PDF" so you can see the while loop at work.

    #!/bin/bash
    INPUT=./Students.csv
    OLDIFS=$IFS
    IFS=,
    [ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
    echo "While "
    while read flname
    do
        echo "cp Rubric.pdf ./Grades/$flname_rubric.PDF"
        cp Rubric.pdf ./Grades/$flname_rubric.PDF
    done < "$INPUT"
    IFS=$OLDIFS