Haegin
November 22nd, 2005, 04:53 PM
Hi, I am trying to write a bash script to install "any" program on linux (provided it uses deb, rpm or source atm). I am kinda picking it up as I go along and its just real basic at the moment but I am having problems. The code so far:
#!/bin/bash
## This script aims to enable users to install a program using a GUI interface as opposed to the command line.
## Unlike other similar offerings it attempts to install rpms, debs and source archives...
## Asks what package
pkgType=`zenity --list --title="Package Type" --text="What type of package are you installing?" --radiolist --column="Check" --column="Package Name" FALSE Deb FALSE Rpm FALSE "Source(tar.bz)" FALSE "Source(tar.gz)"`
## Tells the terminal what package has been chosen.
echo $pkgType
if ["$pkgType" = "Rpm"]; then
echo $pkgType
else
echo "Not an rpm!"
fi
When I run it and select anything (including "Rpm") it echos the correct string but then when it compares it it decides that it isn't "Rpm" even if it is... Does anybody know why?
EDIT: I have now solved that problem using the case...esac conditional. My code now looks like this:
#!/bin/bash
## This script aims to enable users to install a program using a GUI interface as opposed to the command line.
## Unlike other similar offerings it attempts to install rpms, debs and source archives...
## Asks what package
pkgType=`zenity --list --title="Package Type" --text="What type of package are you installing?" --radiolist --column="Check" --column="Package Name" FALSE Deb FALSE Rpm FALSE "Source(tar.bz2)" FALSE "Source(tar.gz)"`
## Tells the terminal what package has been chosen.
#echo $pkgType
case $pkgType in
"Deb" ) echo "Package is a deb" ;;
"Rpm" ) echo "Package is an rpm" ;;
"Source(tar.bz2)" ) echo "Package is a bzipped source archive" ;;
"Source(tar.gz)" ) echo "Package is a gzipped source archive"
esac
As you can see - I added some stuff for the other types. This seems to work - If i get any more probs I will post here.
#!/bin/bash
## This script aims to enable users to install a program using a GUI interface as opposed to the command line.
## Unlike other similar offerings it attempts to install rpms, debs and source archives...
## Asks what package
pkgType=`zenity --list --title="Package Type" --text="What type of package are you installing?" --radiolist --column="Check" --column="Package Name" FALSE Deb FALSE Rpm FALSE "Source(tar.bz)" FALSE "Source(tar.gz)"`
## Tells the terminal what package has been chosen.
echo $pkgType
if ["$pkgType" = "Rpm"]; then
echo $pkgType
else
echo "Not an rpm!"
fi
When I run it and select anything (including "Rpm") it echos the correct string but then when it compares it it decides that it isn't "Rpm" even if it is... Does anybody know why?
EDIT: I have now solved that problem using the case...esac conditional. My code now looks like this:
#!/bin/bash
## This script aims to enable users to install a program using a GUI interface as opposed to the command line.
## Unlike other similar offerings it attempts to install rpms, debs and source archives...
## Asks what package
pkgType=`zenity --list --title="Package Type" --text="What type of package are you installing?" --radiolist --column="Check" --column="Package Name" FALSE Deb FALSE Rpm FALSE "Source(tar.bz2)" FALSE "Source(tar.gz)"`
## Tells the terminal what package has been chosen.
#echo $pkgType
case $pkgType in
"Deb" ) echo "Package is a deb" ;;
"Rpm" ) echo "Package is an rpm" ;;
"Source(tar.bz2)" ) echo "Package is a bzipped source archive" ;;
"Source(tar.gz)" ) echo "Package is a gzipped source archive"
esac
As you can see - I added some stuff for the other types. This seems to work - If i get any more probs I will post here.