geoffn
Posts: 2
Joined: Fri Feb 23, 2018 12:51 pm

Raspberry update shell script - error

Fri Feb 23, 2018 12:56 pm

Hi,

I have the below shell script:

echo “Shell Script to update OS"
#Update System Software
apt-get update
#Upgrade System Software
apt-get upgrade
#Update Distribution Software
apt-get dist-upgrade
#Remove Application Orphans
apt-get autoremove --purge

#Update RaspberryPi Firmware
while true; do
    read -p "Do you wish to update the RaspberryPi Firmware?" yn
    case $yn in
        [Yy]* ) rpi-update; break;;
        [Nn]* ) exit;;
        * ) echo "Please answer yes or no.";;
    esac
Done


when I try and run it I get the following errors:

./updateos.sh: line 17: unexpected EOF while looking for matching `"'
./updateos.sh: line 20: syntax error: unexpected end of file

I checked and I cannot see I have missed a " and the file is executable. I am running it as root using the command ./updateos.sh on the CLI. Can anyone assist?

Thanks in advance

Best Regards

Geoff

User avatar
DougieLawson
Posts: 32722
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Raspberry update shell script - error

Fri Feb 23, 2018 1:44 pm

The simple answer is remove that rpi-update stuff completely. It isn't needed for anyone other than the folks working the the Raspberry Pi Foundation on the leading edge kernel and firmware development.

Running rpi-update can (and has done with my systems) break your system and leave it not bootable.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

n67
Posts: 697
Joined: Mon Oct 30, 2017 4:55 pm

Re: Raspberry update shell script - error

Fri Feb 23, 2018 3:16 pm

while true; do
read -p "Do you wish to update the RaspberryPi Firmware?" yn
case $yn in
[Yy]* ) rpi-update; break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
Done
Or, for a less useless answer, you need "done", not "Done". Shell is a case-sensitive language.

Incidentally, I would do it like this:

Code: Select all

until read -p "Enter yes or no: " yn
     case $yn in
     [Yy]*) echo "You said yes";;
     [Nn]*) echo "You said no";;
     *) echo "Answer the darn question!";false
     esac
do :;done
"L'enfer, c'est les autres"

geoffn
Posts: 2
Joined: Fri Feb 23, 2018 12:51 pm

Re: Raspberry update shell script - error

Fri Feb 23, 2018 4:29 pm

Hi,

thanks for all the suggestion issue now sorted.

Best Regards

Geoff

User avatar
KLL
Posts: 1453
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
Contact: Website

Re: Raspberry update shell script - error

Sun Feb 25, 2018 5:37 am

n67 wrote:
Fri Feb 23, 2018 3:16 pm

Incidentally, I would do it like this: ...
thanks, very good
mod version:

Code: Select all

#!/bin/bash
# test how to ask user
# from https://www.raspberrypi.org/forums/viewtopic.php?f=91&t=206184#p1277225
# KLL rev  25.2.2018

# optional terminal colors
WHT='\E[37;44m'   # white on blue background
BLU='\E[47;34m'   # blue on white background
MAG='\E[47;35m'   # magenta on white background
GRN='\E[47;32m'   # green on NO background
RED='\E[47;31m'   # red on white background
BLK='\E[47;30m'   # black on white background
BOLD='\033[1m'             # and BOLD
END2='\033[0m'             # end bold

# local text variables
MYQUESTION='BASH ask'

MYINFO=' use Yes [Yy] or No [nN] or Quit [qQ] or [CTRL][c] / timeout 30s:'

MYANSWER=''

echo -e $RED$MYQUESTION$END2
#echo -n $MYINFO   # -n if no new line required
echo -e $BLU$MYINFO$END2
# timeout, one character input only / no ENTER required
read -t 30 -n 1 -p '? ' MYANSWER
     case $MYANSWER in
     [Yy]*) echo ' You said: yes'
     # what to do next?
     echo 'yes next'
     ;;
     [Nn]*) echo ' You said: no'
     # what to do next?
     echo 'no next'
     ;;
     [Qq]*) echo ' You said: quit';;
     *) echo ' !wrong answer or timeout';;
     esac
#
geoffn wrote:
Fri Feb 23, 2018 12:56 pm
Hi,

I have the below shell script:
...
Geoff
i am happy with following way for RASPBIAN OS update:

nano .bash_aliases
and add:

Code: Select all

alias update='sudo apt-get update && sudo apt-get -y dist-upgrade'
# if you worry that you will forget your aliases settings you can show as reminder ( at every opened terminal)
echo 'use: .... update, ...'

Return to “Beginners”

Who is online

Users browsing this forum: Bing [Bot] and 54 guests