Question on a Unix Script

Discussion in 'General Mac Discussion' started by starrin, Dec 1, 2004.

  1. starrin macrumors member

    Joined:
    Aug 22, 2004
    #1
    Hello,

    I am trying to create a Unix script to run, now the script I have is phonebook.sh and when I type the

    . ./phonebook.sh

    from the command line it all works fine. However I want to just double click on it and have it work -- for ease of use;-)

    So I changed the extension from .sh to .command and I receive errors.

    Here is my script, can someone tell me what I need to do in order to have it double clickable --- thank you so much. These are all java command line commands:


    #!/bin/sh
    javac -sourcepath source -classpath classes:lib/xerces-1.4.4.jar:lib/log4j-1.2.8.jar:lib/ibx-rt-1.4.0.jar source/com/ibx/commons/example/cmdprocessor/*.java -d classes

    javac -sourcepath source -classpath classes:lib/xerces-1.4.4.jar:lib/log4j-1.2.8.jar:lib/ibx-rt-1.4.0.jar source/com/ibx/commons/example/phonebook/dao/*.java -d classes

    javac -sourcepath source -classpath classes:lib/xerces-1.4.4.jar:lib/log4j-1.2.8.jar:lib/ibx-rt-1.4.0.jar source/com/ibx/commons/example/phonebook/command/*.java -d classes

    javac -sourcepath source -classpath classes:lib/xerces-1.4.4.jar:lib/log4j-1.2.8.jar:lib/ibx-rt-1.4.0.jar source/com/ibx/commons/example/phonebook/*.java -d classes

    java -cp classes:config:lib/xerces-1.4.4.jar:lib/log4j-1.2.8.jar:lib/hsqldb.jar:lib/ibx-rt-1.4.0.jar com.ibx.commons.example.cmdprocessor.CommandProcessor phone-book
     
  2. jeremy.king macrumors 603

    jeremy.king

    Joined:
    Jul 23, 2002
    Location:
    Fuquay Varina, NC
    #2
    I assume this is just to make your development process easier, but I would highly suggest looking into Ant to build your app and then creating either a shell script or runnable jar to execute your compiled application. Ant is a great tool for any java developer.

    You may also want to consider using Eclipse or XCode. Eclipse compiles on the fly and has Ant plugins to help you create a jar file. Plus - you don't have to worry about all the command line madness.
     
  3. starrin thread starter macrumors member

    Joined:
    Aug 22, 2004
    #3
    Hi there,

    I am all too familiar with what you are describing ... this is for a roadmap piece of software for a reusable persistence tier that my company reuses ... similar to Hibernate from a Value Handler sort of way ... just need this for simple demonstrations. We have an ANT script, we use cruise control, and maven.

    Any help is much appreciated.
     
  4. broken_keyboard macrumors 65816

    broken_keyboard

    Joined:
    Apr 19, 2004
    Location:
    Secret Moon base
    #4
    Maybe try making all of the paths absolute - perhaps it doesn't set the current directory when you double click on a .command file.

    There could also be some environment variables it is missing. Try adding
    export $JAVA_HOME=/where/you/have/java

    as the first line after the #! in your script.
     
  5. techgeek macrumors member

    Joined:
    Jun 11, 2004
    Location:
    UK
    #5
    The Apple support page says what you are doing should work.
    http://docs.info.apple.com/article.html?artnum=151597

    One thing I notice though is the way you are running the script from the command line. When you do . ./script.sh you are sourcing the script which means it runs within the current shell as opposed to executing it which means it gets it's own sub-shell to run in.
    This might not sound like much, but it can make a big difference particularly to enviroment variables. Also you don't need the execute permission set to source the file, but you do (obviously) to execute it. Have you set the execute permission on the file?

    Can you post the errors you get?

    I've done quite a bit of unix scripting, but not much on OS X, so treat my answers appropriatly. :)
     
  6. starrin thread starter macrumors member

    Joined:
    Aug 22, 2004
    #6
    Hello -- this did the trick.

    However I have one more question .... some of the code works off of relative paths. It appears that when I change it to a .command type file...it starts the process out of my home directory. How do I tell it to start out of the directory from which it is executed?

    Thanks.
     
  7. jeremy.king macrumors 603

    jeremy.king

    Joined:
    Jul 23, 2002
    Location:
    Fuquay Varina, NC
    #7
    Add a "cd" command to your script.

    To my thoughts before, I was just questioning the script but then I don't quite understand its purpose - I was confused why it has to recompile every time. No worries.
     

Share This Page