Help with shell script

I'm trying to restore the uboot on my GoFlexHome and was told to use the following shell script from github:-
Code:
flash_uboot() {
  if [[ ! -e /dev/mtd0 ]]; then
   echo '>> Error: /dev/mtd0 does not exist.'
   return
  fi
  # set up config for fw_printenv/setenv
  echo '/dev/mtd0 0xc0000 0x20000 0x20000' > /etc/fw_env.config
  # save MAC address
  mac=$(fw_printenv | grep ethaddr | cut -d= -f2)
  if [[ $mac == '' ]]; then
   echo '>> Error: Could not find MAC address from current U-Boot.'
   return
  fi
  # flash U-Boot
  flash_erase /dev/mtd0 0 4
  flash_erase /dev/mtd0 0xc0000 1
  nandwrite /dev/mtd0 /boot/uboot-goflexhome.kwb
  nandwrite -s 0xc0000 /dev/mtd0 /boot/uboot-goflexhome.env
  # set MAC address
  fw_setenv ethaddr ${mac}
}

ask_uboot() {
  echo "A new U-Boot version needs to be flashed to NAND."
  echo "Do you want to do this now? [y|N]"
  read -r shouldwe
  if [[ $shouldwe =~ ^([yY][eE][sS]|[yY])$ ]]; then
   flash_uboot
  else
   echo "You can do this later by re-installing uboot-goflexhome."
  fi
}

## arg 1:  the new package version
post_install() {
  ask_uboot
}

## arg 1:  the new package version
## arg 2:  the old package version
post_upgrade() {
  ask_uboot
}

When I run it I get:-
Code:
27: Syntax error: "(" unexpected (expecting "then")

I'm surprised that there would syntax errors on something that has been on github for three years. Am I missing something?
 
Although I agree with SirDice try putting single quotes around the regular expression on line 27. I think the shell is trying to interpret the regex as some sort of command to be parsed instead of as a string to be used as a regular expression.
 
As far as I know, these are all bash(1) syntax and are not supported by FreeBSD's sh(1):
Code:
if [[ .... ]]; then
Code:
if [[ $var =~ <regexp> ]]; then

And because the script also originates from Linux there's a very high likelihood it's all bash(1), even if the shebang shows #!/bin/sh.
 
As far as I know, these are all bash(1) syntax and are not supported by FreeBSD's sh(1):
Code:
if [[ .... ]]; then
Code:
if [[ $var =~ <regexp> ]]; then

And because the script also originates from Linux there's a very high likelihood it's all bash(1), even if the shebang shows #!/bin/sh.

I keep forgetting that Linux usually replaces sh with bash.
 
Back
Top