bash $INPUT 不明确的重定向

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13167000/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 03:40:06  来源:igfitidea点击:

$INPUT Ambiguous redirect

bashshellcygwin

提问by user1301593

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.

我前段时间写了这个脚本,它运行良好,但由于某种原因,我现在在 cygwin 中收到第 11 行的“模糊重定向”错误消息。

#!/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?

我在这里做错了什么?

回答by Daniel Haley

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

尝试删除等号后的空格INPUT=

回答by Rob Kielty

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

如前所述,删除空格。所以行读INPUT=./Students.csv

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

将 $INPUT 包裹在 "" 中,使其读取 done < "$INPUT"

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

我添加了echo "cp Rubric.pdf ./Grades/$flname_rubric.PDF"以便您可以看到工作中的 while 循环。

#!/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