$INPUT Ambiguous redirect

2019-04-15 16:38发布

问题:

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?

回答1:

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


回答2:

Try removing the space after the equals sign in INPUT=.