![1748048961/source.sh: 133행: 일치하는 ""를 찾는 동안 예기치 않은 EOF가 발생했습니다. 1748048961/source.sh: 138행: 구문 오류: 예기치 않은 파일 끝 [닫힘]](https://linux55.com/image/184247/1748048961%2Fsource.sh%3A%20133%ED%96%89%3A%20%EC%9D%BC%EC%B9%98%ED%95%98%EB%8A%94%20%22%22%EB%A5%BC%20%EC%B0%BE%EB%8A%94%20%EB%8F%99%EC%95%88%20%EC%98%88%EA%B8%B0%EC%B9%98%20%EC%95%8A%EC%9D%80%20EOF%EA%B0%80%20%EB%B0%9C%EC%83%9D%ED%96%88%EC%8A%B5%EB%8B%88%EB%8B%A4.%201748048961%2Fsource.sh%3A%20138%ED%96%89%3A%20%EA%B5%AC%EB%AC%B8%20%EC%98%A4%EB%A5%98%3A%20%EC%98%88%EA%B8%B0%EC%B9%98%20%EC%95%8A%EC%9D%80%20%ED%8C%8C%EC%9D%BC%20%EB%81%9D%20%5B%EB%8B%AB%ED%9E%98%5D.png)
#!/bin/bash
#
#Lisa You
#
#12/1/2020
#
#Purpose of the script: The user can use the script to copy, read, rename, and delete files.
#
#Use of while loop to continue task until the user answers NO to continue the script
CHOICE=YES
while (($CHOICE = “YES”))
do
#Prompting the user to choose an option
PS3="Choose an option from the list above to complete a task: "; export PS3
select OPTION in COPY READ RENAME DELETE HELP EXIT
do
#Copy menu
if [ $OPTION = "COPY" ]; then
read -p "Enter an existing file name: " FILE
#validating file
if [ -f "$FILE" ]; then
continue
else
echo “The $FILE is not a file”
break;
fi
read -p "Enter the destination location: " DEST
#validating directory
if [ -d "$DEST" ]; then
continue;
else
echo "The $DEST is not a directory name."
break;
fi
#checking if file already exists
if ! [[ -f $DEST/$FILE ]];
then
cp "$FILE" "$DEST"
echo "--------------------------------------------------------------------------------"
echo "The task is completed successfully!"
echo "Error Code: $?"
else
echo "$FILE file already exists at this location $DEST”
read -p "Do you want to overwrite the existing file? YES or NO " OPT
if [[ $OPT == "YES" ]]
then
cp "$FILE" "$DEST"
echo "The task is completed successfully!"
echo "Error Code: $?"
else
echo "--------------------------------------------------------------------------------"
echo "The task has failed.!"
echo "Error Code: $?"
break
fi
fi
#Read menu
if [ $OPTION = "READ" ]; then
#validating file
read -p "Enter an existing file name: " FILE
if [ -f "$FILE" ]; then
cat $FILE
echo "Error Code: $?"
else
echo “The $FILE is not a file”
echo "Error Code: $?"
break;
fi
fi
#Rename menu
if [ $OPTION = "RENAME" ]; then
read -p "Which file do you want to rename? Type an existing file name: " FILE
#validating file
if [ -f "$FILE" ]; then
#Prompt for new file name
read -p "Type new file name with an absolute path. " NEWFILE
#Rename file
mv “$FILE” “$NEWFILE”
echo "--------------------------------------------------------------------------------"
echo "The task is completed successfully!"
echo "Error Code: $?"
echo "--------------------------------------------------------------------------------"
echo "The $FILE file is renamed to $NEWFILE."
echo "--------------------------------------------------------------------------------"
else
echo "The $FILE is not a file"
echo "Error Code: $?"
break;
fi
#Delete menu
if [ $OPTION = "DELETE" ]; then
read -p "Which file do you want to delete? Type an existing file name: " FILE
#validate file
if [ -f "$FILE" ]; then
#Ask for confirmation
read -p “Do you want to delete $FILE file? YES or NO” OPT
if [[ $OPT == "YES" ]]
then
#delete file
rm -f $FILE
else
echo "The $FILE is not a file"
break;
fi
fi
fi
#Help menu
if [ $OPTION = "HELP" ]; then
#List what menus do
echo "o Copy: copy a file. FIle to copy, Destinated directory"
echo "o Read: output the contents of a provided file. File to read"
echo "o Rename: rename a file. File to rename, New file name"
echo "o Delete: delete a file. File to delete"
echo "o Help: output a list of supported commands, their actions, and required parameters."
echo "o Exit: exit the script. "
break
fi
#Exit menu
if [ $OPTION = "EXIT" ]; then
exit 0
fi
done
echo "--------------------------------------------------------------------------------"
read -p "Do you want to keep running this script? YES or NO " CHOICE
done
이것은 내 코드이며 다음과 같은 오류가 발생합니다.
1748048961/source.sh: line 133: unexpected EOF while looking for matching `"'
1748048961/source.sh: line 138: syntax error: unexpected end of file
코드를 여러 번 확인했기 때문에 왜 오류가 발생하는지 잘 모르겠습니다. :(
답변1
나는 많은 "정크" 문자를 발견했습니다. 12, 17, 47, 70, 83 및 98행에는 따옴표 대신 다른 문자가 있습니다.
넣지 ==
말고 =
넣어라while (($CHOICE = "YES"))
하나 fi
빠졌네요if [ $OPTION = "COPY" ]; then