Page 1 of 1
Raspberry update shell script - error
Posted: Fri Feb 23, 2018 12:56 pm
by geoffn
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
Re: Raspberry update shell script - error
Posted: Fri Feb 23, 2018 1:44 pm
by DougieLawson
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.
Re: Raspberry update shell script - error
Posted: Fri Feb 23, 2018 3:16 pm
by n67
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
Re: Raspberry update shell script - error
Posted: Fri Feb 23, 2018 4:29 pm
by geoffn
Hi,
thanks for all the suggestion issue now sorted.
Best Regards
Geoff
Re: Raspberry update shell script - error
Posted: Sun Feb 25, 2018 5:37 am
by KLL
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, ...'