Results 1 to 5 of 5

Thread: Simple bash script question

  1. #1
    Join Date
    Apr 2006
    Location
    Arkansas
    Beans
    237
    Distro
    Kubuntu 10.04 Lucid Lynx

    Question Simple bash script question [SOLVED]

    I made a very simple script to get then compile and install the bespin Qt style from SVN and thought I should make it more portable so that other people could use it.

    At first the script assumed that the ~/cloudcity/build directory exists, which it does not on a fresh SVN checkout.

    The problem is that I can't seem to get it to create the build directory on first run then cd into it for the rest of the script.

    This is what I have so far.

    Code:
    #!/bin/bash
    
    # This script will get, then build and install the Bespin style, window decoration, and xbar plasmoid for KDE.
    # You should have all of the build dependencies installed already. Consult your distribution's documentation for instructions on how to do this.
    
    svn co https://cloudcity.svn.sourceforge.net/svnroot/cloudcity
    
    if [ -d ~/cloudcity/build ]; then
        cd ~/cloudcity/build
            while [ ! -d ~/cloudcity/build ]; dwhile [ ! -d ~/cloudcity/build ]; do
            # Sleep until build directory is created
            sleep 1
            done
    else 
        mkdir ~/cloudcity/build
    fi
    
    cmake -DCMAKE_INSTALL_PREFIX=`kde4-config --prefix` ..
    make
    sudo make install
    Last edited by 16777216; March 28th, 2009 at 06:30 AM. Reason: solved

  2. #2
    Join Date
    Sep 2006
    Beans
    2,914

    Re: Simple bash script question

    Quote Originally Posted by 16777216 View Post
    if [ -d ~/cloudcity/build ]; then
    cd ~/cloudcity/build
    while [ ! -d ~/cloudcity/build ]; dwhile [ ! -d ~/cloudcity/build ]; do
    # Sleep until build directory is created
    sleep 1
    done
    else
    mkdir ~/cloudcity/build
    fi
    what is the while loop for?
    Code:
    if [ ! -d ~/cloudcity/build ] ;then
      mkdir ~/cloudcity/build
    fi

  3. #3
    Join Date
    Apr 2006
    Location
    Arkansas
    Beans
    237
    Distro
    Kubuntu 10.04 Lucid Lynx

    Talking Re: Simple bash script question

    Yeah, I was just coming back to say that I figured out that I was kind of going backwards with my if.

    This is what I came up with.

    Code:
    #!/bin/bash
    
    # This script will get, then build and install the Bespin style, window decoration, and xbar plasmoid for KDE.
    # You should have all of the build dependencies installed already. Consult your distribution's documentation for instructions on how to do this.
    
    svn co https://cloudcity.svn.sourceforge.net/svnroot/cloudcity
    
    if [ ! -d ~/cloudcity/build ]; then
        mkdir ~/cloudcity/build
            while [ ! -d ~/cloudcity/build ]; dwhile [ ! -d ~/cloudcity/build ]; do
            # Sleep until build directory is created
            sleep 1
            done
        cd ~/cloudcity/build
    else
        cd ~/cloudcity/build
    fi
    
    cmake -DCMAKE_INSTALL_PREFIX=`kde4-config --prefix` ..
    make
    sudo make install
    Is the while still useless? I will test on my own later to see for myself but I was wondering if it was good to keep for some reason or if their were any unnecessary bits or no-nos in it.

  4. #4
    Join Date
    Sep 2006
    Beans
    2,914

    Re: Simple bash script question

    the while loop is not needed. mkdir will create the directory even before you go into the while loop. mkdir will give you error messages if it can't create directories, so all you need to do, if you want to check for errors, is to grab for the value of return, $?.

  5. #5
    Join Date
    Apr 2006
    Location
    Arkansas
    Beans
    237
    Distro
    Kubuntu 10.04 Lucid Lynx

    Re: Simple bash script question

    Thanks for your help.
    I am still trying to learn scripting and will add layers of complexity on this until it does everything I want it to.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •