Friday, May 3, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 1873  / 2 Years ago, tue, february 22, 2022, 8:32:33

Now no matter what I do it just always says that even with a fi it doesnt do that help me debug the code please. also this has 44 lines of text and it says line 45 also the ascii art is just a dog it might look odd though since we are in a smaller area.



#!/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
        ゙' ' ' ' ' '    ゙' ' ' ' ' '   ゙' ' ' ' ' "

More From » programming

 Answers
1

The error you get is because bash is looking for the end of the if block and can't find it before the end of the file, that's why the error is for line 45.



Now, you have various syntax errors, first of all, an if block looks like this:



if [ test something ]
then
do something
fi


The keywords then and fi are needed. Then, you should quote the variables and strings inside the [ ] test construct, and you should also be aware that your script will break on spaces and unexpected input.



A working version of your script would be:



#!/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


Note that you still have design problems, this is not a well written script, apart from not handling any errors, you also don't exit if any of the choices are entered which means that no matter what I do, I will eventually get to the dog printing. Even if I enter date, you might want to add some exit calls in there.


[#26231] Wednesday, February 23, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rillrage

Total Points: 122
Total Questions: 120
Total Answers: 103

Location: Tokelau
Member since Thu, Aug 26, 2021
3 Years ago
rillrage questions
;