Suppress automatic call to exit in .command files

Discussion in 'Mac Programming' started by kylos, May 5, 2010.

  1. kylos macrumors 6502a

    kylos

    Joined:
    Nov 8, 2002
    Location:
    MI
    #1
    Anybody know how to suppress the automatic call to exit when a .command file is launched from Finder? I want use this to initialize a temporary environment for a single terminal window without changing my standard environment.

    The idea is to click a .command file that sets up an environment and then leave the window open so I can continue working in that environment. I don't want to mess with my standard environment. If there is a better way to achieve this end, I'd love to hear it.
     
  2. kylos thread starter macrumors 6502a

    kylos

    Joined:
    Nov 8, 2002
    Location:
    MI
    #2
    So one solution is to insert all your export statements and other environment-modifying instructions (i.e. cd) in the file and follow it by a call to bash (or whatever shell you prefer). However, it appears that the shell process used to run the file doesn't wait for the second shell to exit, so you can't do something like shut down a server by placing clean-up commands after the bash command (you'll shut down the server while your actual shell is still running).
     
  3. pilotError macrumors 68020

    pilotError

    Joined:
    Apr 12, 2006
    Location:
    Long Island
    #3
    You can put your environment commands into a file and from the terminal prompt, just type in

    . ./myEnvSetup

    This loads the definitions into the current environment.

    Typically, when I do a project, I put the environment setup in a shell script and execute it this way.

    I usually create variables for a path like:

    export MYPROJ_HOME=/whereever
    export MYPROJ_BIN=$MYPROJ_HOME/bin
    ...

    This way you can navigate at the command line

    cd $MYPROJ_HOME

    but mainly because I can make the entire environment for a project generic and be able to change install locations just by editing one file.
     
  4. kylos thread starter macrumors 6502a

    kylos

    Joined:
    Nov 8, 2002
    Location:
    MI
    #4
    I'd been hung up on being able to launch the env from the dock or finder, but sourcing a command file like that is just about as fast and a lot more flexible than a clickable script.
     

Share This Page