-1

I am working on a "on-boot update" bash script, but opening it in the Konsole returns:

~~~~~~-~~~~~@~~~~~~-~~~~~-~~-~~~~~~~~-~~~:~/Documents$ ./update.sh
./update.sh: 3: ./update.sh: [True=True]: not found
~~~~~~-~~~~~@~~~~~~-~~~~~-~~-~~~~~~~~-~~~:~/Documents$

Here is the code (screenshot):

#!/bin.sh
upd=True
while [$upd=True]
do
    echo "Updateing..."
    end=0
    sudo apt-get -yV update
    if [$?=0 -o $end=0]
    then
        end=1
        sudo apt-get -yV upgrade
        if [$?=0 -o $end=1]
        then
            end=2
            sudo apt-get -yV autoremove
            if [$?=0 -o $end=2]
            then
                end=3
                sudo apt-get -yV autoclean
                if [$?=0 -o $end=3]
                then
                    end=4
                    sudo apt-get -yV dist-upgrade
                    if [$?=0 -o $end=4]
                    then
                        end=5
                        sudo apt -yV update
                        if [$?=0 -o $end=5]
                        then
                            end=6
                            sudo apt full-upgrade
                            if [$?=0 -o $end=6]
                            then
                                upd=False
                            fi
                        fi
                    fi
                fi
            fi
        fi
    fi
done
exit 0
trincot
  • 317,000
  • 35
  • 244
  • 286
  • 4
    You should post the code as a text in the question. – SurvivalMachine Jul 04 '16 at 17:10
  • Agreeing with what \@SurvivalMachine said. – sjsam Jul 04 '16 at 17:17
  • 3
    learn to use http://shellcheck.net before posting code here. **AND** don't post screen shots! ;-) Good luck. – shellter Jul 04 '16 at 17:24
  • You should use `if [[ "$upd"="True" ]]` (quotes to prevent issues with empty variables) – Paul Stelian Jul 04 '16 at 19:40
  • @shellter thanks! it (shellcheck.net) helped a lot, still asks for sudo a password though, if you or someone else knows how to deal with that, that would be great. the idea is to update on boot with out having to deal with sudo – Ryan Harrison Jul 05 '16 at 03:48
  • yes, why not recast your Q as just that issue, rather than clutter things up with bad code (OR are you going to update your Q and use the `{}` tool to display your code?) ... That said, `sudo` password issues come up here all the time, so spend a little time reading the highly rated Q/As. Good luck. – shellter Jul 05 '16 at 03:58
  • By the way, the question title says "bash" but your `#!` line says `sh`. They are not the same, even if there is a symbolic link `sh -> bash` since `bash` changes its behaviour when called as `sh`. – cdarke Jul 05 '16 at 06:50
  • @shellter I didn't post the code because I got a "Too much code" error every time i tried to post. Also if you could direct me to some of the Q/As mentioned that would be great (i.e title of the Q/A) I'm not having any luck finding them. – Ryan Harrison Jul 05 '16 at 21:13
  • @cdarke I did not know there was a difference between the two, I just thought that a *.sh shell script was run in bash because "sh" is literally in the name "bash" "Bourne-again shell" – Ryan Harrison Jul 05 '16 at 21:22
  • See http://stackoverflow.com/questions/5725296/difference-between-sh-and-bash – cdarke Jul 06 '16 at 09:20
  • Welcome to Stack Overflow! I edited the question to include the code as text, which makes more sense that including a screenshot. That way visitors can try your code without having to key it in again. Please check whether the text version is correct. – trincot Jul 08 '16 at 17:44

1 Answers1

0

I guess the problem is with

while [$upd=True] #Mind the spaces after [ and before ]

It should have been

while [ "$upd" = True ] #Also the mind spaces before and after =

Note

$upd is put in double quotes to prevent word splitting.

sjsam
  • 21,411
  • 5
  • 55
  • 102