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
Ditto,'while' 루프의 입력은'$ DSWildCardFile'가 펼쳐지는 것입니다. – tripleee
파일이 있는지 확인하는 방법을 변경해야합니다. '[-f $ file]]'을 사용하십시오. 일반적으로 스크립트 내에서'ls '을 사용하고 있다면, 당신은 그것을 잘못하고있다. – jordanm