[英]Why do I keep getting “cp: cannot stat '': No such file or directory” or “cp: missing opereand” in my bash script
[英]Why do I keep getting “Unexpected EOF” in this bash script?
我寫了一個bash腳本,並不斷收到“意外的EOF”錯誤。 我找不到它的問題。 任何人都可以指出我正確的方向。 任何有關如何使其更好的提示也將不勝感激。
這是實際的腳本
figlet -ctf slant "3-Way-Riddles"
toilet -f term -F border --gay "Remember, all the questions have a \"ONE WORD\" answer!!!"
read -p "Please press the [Enter] key to continue: "
read -p "Player One, please enter your name: " playerOne
read -p "Player Two, please enter your name: " playerTwo
one="0"
two="0"
function playerName() {
read -p "Who is answering these questions? " name
if [[ "${name,,}" != "${playerOne,,}" && "${name,,}" != "${playerTwo,,}" ]] ; then
echo -e "Wrong name input, please enter your name again.\n"
playerName
fi
}
function points() {
if [ "$name" = "$playerOne" ] ; then
one=$((one+1))
return $one
else
two=$((two+1))
return $two
fi
}
function echoPoints() {
echo -e "$playerOne has $one points\n$playerTwo has $two points"
}
function progress() {
if [ "$one" -gt "$two" ] ; then
echo Winner is \$playerOne with \$one points.
exit 0
elif [ "$one" -lt "$two" ] ; then
echo Winner is \$playerTwo with \$two points.
exit 0
else
questions ~/TechnicalWritting/Random.txt
fi
}
function questions() {
line="$(wc -l $1 | awk '{print $1}')"
for (( x = 1 ; x <= 2 ; x++ )) ; do
for (( i = 1 ; i <= "$line" ; i++ )) ; do
read -p "$(head -$i $1 | tail -1 | awk -F _ '{print $1}')" ans
if [ "$ans" = "" ] ; then
echo 2&1 Sorry, wrong answer.
elif [ "$ans" = "$(head -$i $1 | tail -1 | awk -F _ '{ print $2 }'" ] ; then
echo Good job random fella.
points
else
echo 2&1 Sorry, wrong answer.
fi
done
done
}
questions ~/TechnicalWritting/Math.txt
questions ~/TechnicalWritting/Logic.txt
questions ~/TechnicalWritting/Funny.txt
progress
你的錯誤在這一行:
elif [ "$ans" = "$(head -$i $1 | tail -1 | awk -F _ '{ print $2 }'" ] ; then
$()
缺少結束)
elif [ "$ans" = "$(head -$i $1 | tail -1 | awk -F _ '{ print $2 }')" ] ; then
建議:1。我認為它是一個bash腳本。 第一行應該是
#! /bin/bash
2.使用帶語法高亮的編輯器。 我正在使用凱特,還有許多其他人也可以使用。 使用kate,我直截了當地發現了你的語法錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.