首页 > 解决方案 > Shell 脚本错误:“文件意外结束”

问题描述

添加代码(第 78 - 134 行)后,我一直收到以下错误。在添加此代码之前,一切正常!
一些额外的信息;我将此 .sh 文件用作“链接”到另一个 .sh 文件的原始 github 文件。这是安装/自托管不和谐机器人的代码(基于 Nadeko)。

$root/TCU_installer_latest.sh:第 151 行:语法错误:文件意外结束

(.sh 文件称为“TCU_installer_latest.sh”)

这是代码;

1. #!/bin/sh
2. clear
3. echo "TCU Installer started."
4. 
5. if hash git 1>/dev/null 2>&1
6. then
7.     echo ""
8.     echo "Git Installed."
9. else
10.     clear
11.     echo "Git is not installed."
12.     echo 'Git installation; "sudo apt-get install git"'
13.     echo ""
14.     echo 'Press CTRL + C to exit.'
15.     echo "Program will automatically exit after 60 seconds."
16.     sleep 60s
17.     exit 0
18. fi
19. 
20. 
21. if hash dotnet 1>/dev/null 2>&1
22. then
23.     echo ""
24.     echo "Dotnet installed."
25. else
26.     echo ""
27.     echo "Dotnet is not installed."
28.     echo 'Dotnet installation; "https://dotnet.microsoft.com/download"'
29.     echo ""
30.     echo 'Press CTRL + C to exit.'
31.     echo "Program will automatically exit after 60 seconds."
32.     sleep 60s
33.     exit 0
34. fi
35. 
36. root=$(pwd)
37. tempdir=TCU_Temp
38. 
39. rm -r "$tempdir" 1>/dev/null 2>&1
40. mkdir "$tempdir"
41. cd "$tempdir"
42. 
43. clear
44. echo "Downloading TCU, please wait."
45. echo ""
46. echo "This process usually takes about 15 seconds."
47. sleep 5s
48. git clone -b Latest_version --recursive --depth 1 (link removed but works fine in actual code)
49. clear
50. echo "TCU downloaded."
51. 
52. echo ""
53. echo "Downloading TCU dependencies"
54. echo ""
55. echo "This process usually takes about 10 seconds."
56. sleep 5s
57. cd "$root/$tempdir/TCU"
58. dotnet restore
59. clear
60. echo "TCU Dependecies are downloaded"
61. 
62. echo ""
63. echo "Building TCU for you!"
64. echo ""
65. echo "This process usually takes about 10 seconds."
66. sleep 5s
67. dotnet build --configuration Release
68. clear
69. echo "Build done."
70. sleep 3s
71. 
72. cd "$root"
73. 
74. if [ ! -d TCU ]
75. then
76.     mv "$tempdir"/TCU TCU
77. else
78.     echo 'You already have a directory called "TCU" in this folder.'
79.     echo ""
80.     cd $root
81.     choice=5
82.     echo "1. Delete the original TCU folder and retry your download."
83.     echo '2. Rename the original TCU folder (-> "TCU_Old") and retry your download. (recommended)'
84.     echo "3. Don't touch the original TCU folder and retry your download."
85.     echo "4. Exit."
86.     echo ""
87.     echo -n "Choose one of above options (to force quit -> CTRL + C)"
88.     while [ $choice -eq 5 ]; do
89.     read choice
90.     if [ $choice -eq 1 ] ; then
91.       echo ""
92.       echo 'Deleting "TCU"'
93.       rm -rf TCU
94.       sleep 2s
95.       echo ""
96.       echo 'Retrying TCU latest/stable build.'
97.       sleep 3s
98.       bash $root/TCU_installer_latest
99. 
100.       else if [ $choice -q 2 ]; then
101.         echo ""
102.         echo 'Renaming "TCU" to "TCU_Old"'
103.         mv $root/TCU TCU_Old
104.         sleep 2s
105.         echo ""
106.         echo 'Retrying TCU latest/stable build.'
107.         sleep 3s
108.         bash $root/TCU_installer_latest
109. 
110.         else if [ $choice -q 3 ]; then
111.           echo ""
112.           echo 'Retrying TCU latest/stable build.'
113.           sleep 3s
114.           bash $root/TCU_installer_latest
115.           else if [ $choice -q 4 ]; then
116.             echo ""
117.             echo "Exciting.."
118.             sleep 2s
119.             cd $root
120.             exit 0
121.             else
122.               clear
123.               echo "1. Delete the original TCU folder and retry your download."
124.               echo '2. Rename the original TCU folder (-> "TCU_Old") and retry your download. (recommended)'
125.               echo "3. Don't touch the original TCU folder and retry your download."
126.               echo "4. Exit."
127.               echo ""
128.               echo -n "Choose one of above options (to force quit -> CTRL + C)"
129.               choice=5
130.           fi
131.         fi
132.       fi
133.     fi
134. done
135. 
136. rm -r "$tempdir"
137. clear
138. echo "Installation Complete."
139. echo "TCU has been installed successfully!"
140. echo ""
141. echo "Thanks for using TCU <3"
142. echo ""
143. echo 'Press CTRL + C to exit.'
144. echo "Program will automatically exit after 60 seconds."
145. cd "$root"
146. rm "$root/TCU_installer_latest.sh"
147. sleep 60s
148. 
149. cd $root
150. exit 0

提前感谢<3

标签: shellsh

解决方案


推荐阅读