现在,无论我做什么,都总是说即使有fi也不能帮我调试代码。它也有44行文字,它说第45行也就是ascii艺术,不过由于我们位于较小的区域,它看起来可能很奇怪。
#!/bin/bash
clear
echo "Hello Sir How are you? These are some of my features
date
picture"
read word
if [ $word = picture ]
echo "These are the following pictures I have at my disposel:
Dog"
if [ $word = date ]
w
fi
read word
if [ $word = dog ]
fi
echo "
__,-;;;\
/;;;;;;;;;;;;;;;/ l \ヽ | /___
/;;;;;;;;;;;;;;/ ヽ;;;;;;\
ヽ;;;;;;;;;;;ノ |;;;;;;;;;;;l
/ ̄~~ |;;;;;;;;;;;;l
フ ○ \;;;;;ノ
,-~~ ○ ヽ,,,,,,,,,,,,,,、 , , ,
~/ ● \,;;;;;;;;;;;;;;;;;;,V;;;;;;;;;゙,
l_,,, >,;;;;;;;;;;;;;;;;;;;;;;ヽ;;;;;;;,゙
|/l /l , ヽ |ヽl,;;;;;;;;;;;;;;;;;;;;;;;;;;;;i- ''
Y V ヽllノ レ ヽ)V;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;j
゙, ' ' ' ' ' ' ,',,'
゙, ヽ-,,,,,,,,゙, ゙ ゙
゙, ゙, ,゙ ゙ ゙,゙゙゙゙゙, .,゙
゙, ,゙ ゙,,,゙, ゙, ゙, ,l
゙' ' ' ' ' ' ゙' ' ' ' ' ' ゙' ' ' ' ' "
您得到的错误是因为bash正在查找if
块的末尾,而在文件末尾之前找不到它,这就是错误出现在第45行的原因。
现在,您遇到各种语法错误,首先,一个代码if
块如下所示:
if [ test something ]
then
do something
fi
关键字then
和fi
是必需的。然后,应在[ ]
测试构造中引用变量和字符串,并且还应注意脚本将在空格和意外输入上中断。
您的脚本的有效版本为:
#!/bin/bash
clear
echo "Hello Sir How are you? These are some of my features
date
picture"
read word
if [ "$word" = "picture" ]
then
echo "These are the following pictures I have at my disposel:
Dog"
fi
if [ "$word" = "date" ]
then
w
fi
read word
if [ "$word" = "dog" ]
then
echo "
__,-;;;\
/;;;;;;;;;;;;;;;/ l \ヽ | /___
/;;;;;;;;;;;;;;/ ヽ;;;;;;\
ヽ;;;;;;;;;;;ノ |;;;;;;;;;;;l
/ ̄~~ |;;;;;;;;;;;;l
フ ○ \;;;;;ノ
,-~~ ○ ヽ,,,,,,,,,,,,,,、 , , ,
~/ ● \,;;;;;;;;;;;;;;;;;;,V;;;;;;;;;゙,
l_,,, >,;;;;;;;;;;;;;;;;;;;;;;ヽ;;;;;;;,゙
|/l /l , ヽ |ヽl,;;;;;;;;;;;;;;;;;;;;;;;;;;;;i- ''
Y V ヽllノ レ ヽ)V;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;j
゙, ' ' ' ' ' ' ,',,'
゙, ヽ-,,,,,,,,゙, ゙ ゙
゙, ゙, ,゙ ゙ ゙,゙゙゙゙゙, .,゙
゙, ,゙ ゙,,,゙, ゙, ゙, ,l
゙' ' ' ' ' ' ゙' ' ' ' ' ' ゙' ' ' ' ' "
fi
请注意,您仍然存在设计问题,这不是一个编写良好的脚本,除了不处理任何错误外,如果输入了任何选项,您也不会退出,这意味着无论我做什么,最终我都会狗印刷。即使输入date
,您也可能要在其中添加一些exit
呼叫。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句