Note that there are some explanatory texts on larger screens.

plurals
  1. POBash Verification and Conditional Statements
    primarykey
    data
    text
    <p>I am in the process of writing an install script for a program in bash. The first part of the install detects whether the program is already installed or not. This is detected by the presence of a file in a specified directory. That part works fine. However, I want the user to be able to upgrade to the new version if the old version exists. I thought I had the code right, but it doesn't quite work. There is a file in /var/www/html/gvsms called .version that simply has the version of the program in the file. I want to compare that number to the number of the installer. I'm not sure how, though, inside an if statement. Can there be multiple Ifs inside an If? This is what I have so far:</p> <pre><code>$installerver=1.1 $installedver=${cat /var/www/html/gvsms/.version} echo "Installation beginning...." echo " " echo " " echo -n "Checking to see if GVoice SMS Notification System was previously installed..." if [ -a /var/www/html/gvsms/index.php ]; then echo "Yes." echo "" echo "I have detected a previous installation of GVoice SMS Notification System." if [ $installerver == $installedver ]; then echo "The GVoice SMS Notification System is currently installed and is the same version as this installer. If you were trying to upgrade, please check the installer you downloaded and try again." exit fi elif [ $installedver == "0.5" || $installedver == "1.0"]; then while [[ "$yn" != "Yes" &amp;&amp; "$yn" != "Y" &amp;&amp; "$yn" != "y" &amp;&amp; "$yn" != "yes" ]]; do echo "Would you like to upgrade? Yes or no." read -r upgrade echo "$upgrade upgrade?" echo "Is this correct? (Yes or No)" read yn done echo "Upgrade proceeding..." fi echo "No." echo "I have not detected a previous installation of GVoice SMS Notification System." read -p "To proceed with installation at your own risk, press Enter. Otherwise Ctrl-C." </code></pre> <p>Right now the program errors out with:</p> <pre><code>./test.x: line 1: =1.1: command not found ./test.x: line 2: ${cat /var/www/html/gvsms/.version}: bad substitution </code></pre> <p>The way the program should work is that if the file is detected, installed version is not (or less than) the same as the installer, and the user says yes to upgrade, the upgrade commands should run. If the user says no to upgrade, then exit the script.</p> <p>If the program is installed and is the same version as the installer, display error message and exit.</p> <p>If the program is not already installed, skip reconfirm installation and proceed with normal install.</p> <p>Is this possible? Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload