Я делаю сценарий (для образовательных целей), но я застрял здесь ... Программа запрашивает существующее имя файла и проверяет, существует ли имя файла на самом деле. Если это не так, цикл повторяется, пока вы не заполните файл, который существует. Все идет нормально! Но когда вы вводите имя файла, которое существует, я хочу, чтобы скрипт вводил следующий цикл while для ввода файла пути. Но он не продолжается. Как я могу сделать, чтобы ввести следующее в то время как заявление ???
clear
echo "Your filesystem is threatned, files should be moved in order to guarantee safety!!!!"
while read FILE
do
if [ -f $FILE ];
then
echo "File is safe to secure"
else
echo "Too late, we lost the file, safe another!"
fi
done
echo "Time is running out, we must secure this file inmidiately, quick give me a safe location!"
while read PATH
do
if [ -d $PATH ] && [ -f $FILE ];
then
echo "the location is secure! Move the file!"
else
echo "Either the file or the safehouse is corrupt, quick try again!"
fi
done
Это работает:
clear
echo "Your filesystem is threatned, files should be moved in order to guarantee safety!!!!"
while read file; do
if [[ -f "$file" ]]; then
echo "File is safe to secure"
break
else
echo "Too late, we lost the file, safe another!"
fi
done
echo "Time is running out, we must secure this file inmidiately, quick give me a safe location!"
while read path; do
if [ -d "$path" ]; then
echo "the location is secure! Move the file!"
break
else
echo "Either the file or the safehouse is corrupt, quick try again!"
fi
done
Вы должны добавить операторы break
, чтобы выйти из цикла, когда найден правильный файл / путь. Также не используйте ЗАГЛАВНЫЕ БУКВЫ для имен переменных.