0
我有一个脚本,用于检查文件是否存在或不使用ls命令。如果没有文件,我会询问用户是否想继续使用该脚本。在无限循环中使用读命令的怪异行为
我在找的是,除了从终端输入而不是键盘输入的读命令?
这里是我的脚本:
function isfileThere(){
output=$(ls ${1} 2>&1 >/dev/null)
case $output in
*"No such file or directory"*)
echo "DS not found: $output";
option_exitprog; $output >> DSNotFound.txt ;;
*) echo "DS found: $output";;
esac
}
function option_exitprog(){
while :
do
echo -n "Would you like to continue (y/n)?"
read Answer
#read -n1 -p "Would you like to continue (y/n)?" Answer
if [ ! -z "$Answer" ] ; then
if [ "$Answer" == "y" ] ; then
echo "Exiting script. Goodbye"
exit 1
elif [ "$Answer" == "n" ] ; then
echo "Continue With Program"
break
else
echo "We only accept (y/n)"
fi
else
echo "You have entered a null string. We only accept (y/n)"
fi
done
}
function get_TotalEventEntries(){
cat<<EOF
####################################
# #
# #
# get Total Entries #
# #
# #
####################################
EOF
while read LINE
do
let total_DSNumber=total_DSNumber+1
#Check if files exist
isfileThere ${FileDir}/*${LINE}*/*.root*
#print to file
#printf "${LINE}=" >> ${Filename}
#getEntries ${LINE} >> ${Filename}
done < ${DSWildCardFile}
echo "Finished running over $total_DSNumber file(s)"
}
get_TotalEventEntries
其中是您的var DSWildCardFile定义?此外,如果您编辑帖子以指示预期行为,可能会有所帮助。你看到任何错误消息?你的意思是接受还是期待(而不是除外)?您是否尝试过通过在脚本顶部附近添加'set -vx'来进行调试?祝你好运。 – shellter 2012-02-15 20:06:30
同上,'while'循环的输入是'$ DSWildCardFile'扩展到的任何内容。 – tripleee 2012-02-15 20:22:40
您应该更改检查文件是否存在的方法。使用:'if [[-f $ file]]'。一般来说,如果你在脚本中使用'ls',那么你做错了。 – jordanm 2012-02-15 20:33:25