I am forming a new question based on an earlier one I posted here in regards to a BASH Script I am writing. This is only one function of the script but I started here because I figured I would have best success with completing this function over others.
The code that I have thus-far is:
#!/bin/bash
clear;
welcome="- Sudo Bypass Package Installer -";
echo $welcome;
pkgFetch() {
echo -n "Name of package you would like to install: "; read pkg
chkPkg=$(dpkg -s $pkg|grep installed); echo "The Package [$pkg] is already installed."
if [ "" == "$chkPkg" ]; then
echo "The Package [$pkg] is installing..."
sudo apt-get install $pkg -qq
echo "The package [$pkg] was successfully installed."
fi
echo -n "Press ENTER to return to command-line."
};
pkgFetch;
read;
clear;
The first part, which checks if the package is installed (if it is the script returns the message stating it's already installed) appears to be working correctly. However, I encounter a few things here that I can't make sense of...mostly because I am a novice.
- If [$pkg] is not installed, the script still displays the message saying that it is, followed by the message that should be displayed if not installed, which is that it is currently installing.
- The script doesn't silently install the package. It shows that it is reading database, unpacking $pkg, processing triggers, and setting up $pkg. Afterwards, the script displays the correct message that "The package [$pkg] was successfully installed".
Anyone want to take a shot at it here and educate me about my errors?
Thanks in advance : - )
if [ "$pkg" == "$chkPkg" ]; then ...
but it displayed $chkPkg as part of the written string rather than a variable. – Kevin Wyman Oct 28 '12 at 10:39[
is a program (yes, the one you use in an if statement). Seeman [
orman test
to learn what I mean by nonempty. – Paul Hänsch Oct 28 '12 at 15:46