这里是我的脚本:为什么在运行bash脚本时出现意外的文件错误结束?
#!/bin/bash
if [ $# -lt 2 || $# -gt 3 ]; then # invalid number of arguments given
echo "usage: minor3 name [euid]"
else # valid number of arguments given
echo Good day, $1! Nice to meet you!
CHOICE=1
while [ "$CHOICE" -gt 0 && "$CHOICE" -lt 4 ] # print out the menu, obtain user choice, execute appropriate system call using if-else statements, loop if desired
do
echo "+*******************************************************************+
Enter one of the following options: |
1) List and count all non-hidden files in the current directory. |
2) Check if given user (default = current user) is logged in, then |
... list all active processes for that user. |
3) List the sizes and names of the 10 largest files and directories |
... in the current directory. |
4) Exit this shell program. |
+*******************************************************************+
> "
read CHOICE
if [ "$CHOICE" = 1 ]; then
# list and count all files
echo test
fi
if [ "$CHOICE" = 2 ]; then
if [ $# = 3 ]; then # euid was given
# use given user ($2)
echo given user
else
# use current user
echo current user
fi
fi
if [ "$CHOICE" = 3 ]; then
# list sizes and names of 10 largest files/directories
echo test
fi
done
echo Thanks, $1! Have a great day!
fi
这是我得到的错误:51
[email protected]:~/3600/min3$ chmod +x minor3.sh
[email protected]:~/3600/min3$ ./minor3.sh
./minor3.sh: line 51: syntax error: unexpected end of file
线是最后fi
后的行,即最后一行后,我行程序。我发现一个较早的堆栈溢出的职位,说要用DOS2UNIX的,但是Linux服务器一定要考就由我校拥有的,所以我没有把它安装能力,使得它不是一个选项。服务器使用Linux Ubuntu 12.04.5 LTS,如果这有所作为。
如果我复制你的代码片段并将其粘贴到我的Vim,他最后'fi'是39行,不就行了50 ... – eckes
也许只是一个格式差异。整个计划在那里。 –
@eckes错误的行号来自dos与unix行结束问题。 – jofel