1

My problem is that i don't understand why when I run the script if i write "yes" or "no" it always says I'm quitting the script. I know that it doesn't recognise $reply and "yes" as equal but why? (I am new in bash programming). Thanks!

#!/bin/bash
clear
echo 'This script will install: Firefox 17.0.1 (language: enGB or itIT or enUS) and flash 11 in Firefox17.0.1, continue?'
read reply
if (( "$reply" = "yes" )); then
  pkill firefox
  rm -rf /tmp/fox
  mkdir /tmp/fox
  cd /tmp/fox
  rm -rf /opt/firefox/*
  rm -rf /usr/lib/mozilla/plugins/*
  rm -f /usr/share/icons/mozicon128.png
  mkdir /usr/lib/mozilla/plugins
  mkdir /opt/firefox
  echo "Enter your language (exmp: it en us)"
  read reply1
  if (( "$reply1" = "it" )); then
    wget ftp://ftp.mozilla.org/pub/mozilla.org/firefox/releases/latest/linux-x86_64/it-IT/firefox-17.0.1.tar.bz2
  elif (( "$reply1" = "en" )); then
    wget ftp://ftp.mozilla.org/pub/mozilla.org/firefox/releases/latest/linux-x86_64/en-GB/firefox-17.0.1.tar.bz2
  else
    wget ftp://ftp.mozilla.org/pub/mozilla.org/firefox/releases/latest/linux-x86_64/en-US/firefox-17.0.1.tar.bz2
  fi
  wget http://fpdownload.macromedia.com/get/flashplayer/pdc/11.2.202.258/install_flash_player_11_linux.x86_64.tar.gz
  wget http://upload.wikimedia.org/wikipedia/commons/7/76/Mozilla_Nightly_icon_2011.png

  tar -xvf firefox-17.0.1.tar.bz2
  tar -xvf install_flash_player_11_linux.x86_64.tar.gz

  cp -R firefox/* /opt/firefox
  cp libflashplayer.so /usr/lib/mozilla/plugins/
  rm -f /opt/firefox/icons/mozicon128.png
  cp -f Mozilla_Nightly_icon_2011.png /opt/firefox/icons/mozicon128.png
  echo "Reboot the system to show the new icon?"
  read response
  if (( "$response" = "yes" )); then
    reboot 
  else
    echo 'Installation Complete'
  fi
else
  echo "I'm quitting the script..."
  exit
fi
seliopou
  • 2,896
  • 20
  • 19
  • If you're confused with different parentheses types: http://stackoverflow.com/questions/2188199/bash-double-or-single-bracket-parentheses-curly-braces – Ixanezis Jan 05 '13 at 06:40
  • 1
    As an aside, forcibly removing stuff out of `/usr` is rarely a good idea. Create a package for your pkatform (RPM? Deb? Gentoo? You're not saying) and install it the normal way. – tripleee Jan 05 '13 at 07:45
  • 1
    You need `[[ ]]` not `(( ))` - also +1 for @tripleee - make a package/formula/recipe whatever for you system to handle uninstalling. – ocodo Jan 05 '13 at 09:00

3 Answers3

6

You're using an arithmetic expression block (( )) to compare strings. Chaos will ensue.

read -p 'This script will install: Firefox 17.0.1 (language: enGB or itIT or enUS) and flash 11 in Firefox17.0.1, continue?' reply
if [[ "$reply" = "yes" ]]; then
    …
kojiro
  • 74,557
  • 19
  • 143
  • 201
3

Double parenthesis (( ... )), when used with an if/then construct, return an exit status according to the evaluation of the integer test expression they are embracing. For instance, the test ((5 == 5)) would evaluate true (i.e. 0).

Standalone, double parenthesis allow for you to use arithmetic evaluations like i=$(( 2+3 )), and/or c-style syntax, like

(( i = 1 )) #or 
(( i++ )) #or 
for ((i=0;i<5;i++)); do ...; done

However, in your code, while you are trying to evaluate variable comparison expressions, you are in fact testing against a c-style assignment. (( "$reply" = "yes" )) does neither compare integers nor any other values, but simply assigns a numerical conversion of the string "yes" to a variable identified by the content of $reply and returns the assigned value as its exit status.

yes converts to 0. In the case that a user entered yes as their reply, the effect will be the assignment

yes=0

Given that, the if statement is merely testing for an integer value to be nonzero, so since the assigned value in the parenthesis is zero, it will return a 1 as an exit code, which means false, and the then block will not be executed. Unless the user enters a nonzero integer value.

Change parenthesis to double-brackets [[...]] and you will be fine. If you prefer to use = or == as an operator doesn't matter in this case.

if [[ "$reply" = "yes" ]]; then

You will find useful answers on this site when in need for further details.

J. Katzwinkel
  • 1,923
  • 16
  • 22
0

Run this script, It worked for me with no errors and got my flash player working.

# Prepare Directory's
pkill firefox
mkdir /tmp/fox
cd /tmp/fox
rm -rf /opt/firefox/*
rm -rf /usr/lib/mozilla/plugins/*
rm -f /usr/share/icons/mozicon128.png
mkdir /usr/lib/mozilla/plugins
mkdir /opt/firefox

# Download Resources
wget http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/latest/linux-x86_64/en-US/firefox-18.0.tar.bz2
wget http://fpdownload.macromedia.com/get/flashplayer/pdc/11.2.202.258/install_flash_player_11_linux.x86_64.tar.gz
wget http://upload.wikimedia.org/wikipedia/commons/7/76/Mozilla_Nightly_icon_2011.png

# Extract Resources
tar -xvf firefox-18.0.tar.bz2
tar -xvf install_flash_player_11_linux.x86_64.tar.gz

# Install
cp -R firefox/* /opt/firefox
cp libflashplayer.so /usr/lib/mozilla/plugins/
#Restart Backtrack to reload start menu icon's or goto menu editor and reselect icon
cp -f Mozilla_Nightly_icon_2011.png /usr/share/icons/mozicon128.png

# Done
echo 'Installation Complete'
Alex
  • 1