Может ли кто-нибудь взглянуть на этот код и выяснить, что с ним не так?
#!/bin/sh
while :
do
echo " Select one of the following options:"
echo " d or D) Display today's date and time"
echo " l or L) List the contents of the present working directory"
echo " w or W) See who is logged in"
echo " p or P) Print the present working directory"
echo " a or A) List the contents of a specified directory"
echo " b or B) Create a backup copy of an ordinary file"
echo " q or Q) Quit this program"
echo " Enter your option and hit <Enter>: \c"
read option
case "$option" in
d|D) date
;;
l|L) ls $PWD
;;
w|w) who
;;
p|P) pwd
;;
a|A) echo "Please specify the directory and hit <Enter>: \c"
read directory
if [ "$directory = "q" -o "Q" ]
then
exit 0
fi
while [ ! -d "$directory" ]
do
echo "Usage: "$directory" must be a directory."
echo "Re-enter the directory and hit <Enter>: \c"
read directory
if [ "$directory" = "q" -o "Q" ]
then
exit 0
fi
done
printf ls "$directory"
;;
b|B) echo "Please specify the ordinary file for backup and hit <Enter>: \c"
read file
if [ "$file" = "q" -o "Q" ]
then
exit 0
fi
while [ ! -f "$file" ]
do
echo "Usage: \"$file\" must be an ordinary file."
echo "Re-enter the ordinary file for backup and hit <Enter>: \c"
read file
if [ "$file" = "q" -o "Q" ]
then
exit 0
fi
done
cp "$file" "$file.bkup"
;;
q|Q) exit 0
;;
esac
echo
done
exit 0
Есть некоторые синтаксические ошибки, которые я не могу понять. Однако я должен отметить, что в этой системе unix echo -e не работает (не спрашивайте меня, почему я не знаю, и у меня нет никаких разрешений на его изменение, и даже если бы мне не разрешили к)
Ошибка сценария оболочки Bash: «./myDemo ./myDemo: строка 62: синтаксическая ошибка рядом с неожиданным токеном done' ./myDemo: line 62:
» [отредактировано]
EDIT: я исправил ошибку оператора while, однако теперь, когда я запускаю скрипт, некоторые вещи по-прежнему работают неправильно.
Похоже, что в операторе b|B) switch
cp $file $file.bkup фактически не копирует файл в file.bkup ?
В операторе a|A) switch
ls "$directory" не выводит список каталогов для просмотра пользователем ?
#!/bin/bash
while $TRUE
do
echo " Select one of the following options:"
echo " d or D) Display today's date and time"
echo " l or L) List the contents of the present working directory"
echo " w or W) See who is logged in"
echo " p or P) Print the present working directory"
echo " a or A) List the contents of a specified directory"
echo " b or B) Create a backup copy of an ordinary file"
echo " q or Q) Quit this program"
echo " Enter your option and hit <Enter>: \c"
read option
case "$option" in
d|D) date
;;
l|L) ls pwd
;;
w|w) who
;;
p|P) pwd
;;
a|A) echo "Please specify the directory and hit <Enter>: \c"
read directory
if [ ! -d "$directory" ]
then
while [ ! -d "$directory" ]
do
echo "Usage: "$directory" must be a directory."
echo "Specify the directory and hit <Enter>: \c"
read directory
if [ "$directory" = "q" -o "Q" ]
then
exit 0
elif [ -d "$directory" ]
then
ls "$directory"
else
continue
fi
done
fi
;;
b|B) echo "Specify the ordinary file for backup and hit <Enter>: \c"
read file
if [ ! -f "$file" ]
then
while [ ! -f "$file" ]
do
echo "Usage: "$file" must be an ordinary file."
echo "Specify the ordinary file for backup and hit <Enter>: \c"
read file
if [ "$file" = "q" -o "Q" ]
then
exit 0
elif [ -f "$file" ]
then
cp $file $file.bkup
fi
done
fi
;;
q|Q) exit 0
;;
esac
echo
done
exit 0
Другое дело... есть ли редактор, который я могу использовать для автоматического анализа кода? То есть что-то похожее на NetBeans?