Execute commands in modified environment
0 Comments Published February 27th, 2009 in Java, Linux Tags: .I'm working on different projects, and every project has its own requirements: jvm, eclipse version (with specific plugins), tomcat version, ant version, etc... Initially I was modifying manually the ~/.bashrc or ~/.profile settings, commenting and uncommenting sections. But this process doesn't scale: it's error prone, your shell profile settings quickly becomes unmaintainable, etc. etc.
So I come out with a simple solution copying the sudo pattern. Sudo is meant to execute commands as a different user. What I needed is a way to execute command in a different environment.
I created a list of scripts, one per project/team where I store environment settings and macros to ease my job. For example, recently I was developing in a team that has been called "monstersinc" (not my fault: I'm ugly but not so ugly); so I created a little bash script to run my IDE and tools with the settings required by the team, and I called "modo" (monstersinc do). Here's it:
#! /bin/bash
# environment settings
JAVA5_HOME=/usr/lib/jvm/java-1.5.0-sun
JAVA6_HOME=/usr/lib/jvm/java-6-sun
export JAVA_HOME=$JAVA5_HOME
export JETTY_HOME=/home/luigi/opt/jetty-6.1.14
export PATH=$JAVA_HOME/bin:$PATH
export ANT_HOME=/usr/share/ant
# specific functions to ease monstersinc development
# specific eclipse installation for monstersinc
function eclipse() {
# use java6 to start eclipse
export JAVA_HOME=$JAVA6_HOME
PATH_BAK=$PATH
export PATH=$JAVA_HOME/bin:$PATH
export LD_LIBRARY_PATH=/usr/lib/jni
~/monstersinc/eclipse/eclipse ${*} &
export PATH=$PATH_BAK
}
# execute the command line
if [ -n "${*}" ]; then
${*}
fi
So, when I want to start eclipse for monstersinc team work, or I want to compile using ant I execute:
$ modo eclipse $ modo ant
I keep a list of environments *do in my ~/bin directory which is in my unix shell PATH. For example I have also a "j5do" and "j6do" for running applications and jdk tools of a specific version of Java with a proper environment (JAVAHOME/PATH/etc)
That's an example of an IT problem that can be solved with an additional level of indirection.
All problems in computer science can be solved by another level of indirection
--David Wheeler
...except for the problem of too many layers of indirection.
--Kevlin Henney
... which are in the most common problems.
Search
Calendar
| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| « Jan | Mar » | |||||
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | |
Archives
Categories
- Android (3)
- Apple (26)
- Books (7)
- Eclipse (14)
- Errors (3)
- Firefox (7)
- Git (2)
- Hardware (16)
- Horror Code (8)
- Internet (18)
- Java (98)
- JavaScript (9)
- Life, universe and everything (45)
- Lifehacks (25)
- Linux (50)
- Opinions (25)
- OSX (4)
- Python (1)
- Software (27)
- Speeches and Conferences (8)
- Unix (3)
- Web (21)
- Windows (19)
Tag Cloud
Android apple architecture Bash colors configuration CSS Development Düsseldorf Eclipse germany Git Google Hardware hdr How-To Java JAXB job junit Karmic Linux MacBook music night Open Source Opinion oracle OSX patterns Pitfalls Practices Resume Security Software Suspend TDD Testing tip tonemapped Tricks Ubuntu video Web XML
WP Cumulus Flash tag cloud by Roy Tanck and Luke Morton requires Flash Player 9 or better.
Blog License
Blogs I like
Books on the desk
Friends' Blogs
- Antonio Terreno & Valter Bernardini
- Bruno Bossola
- Daniele Galluccio
- Domenico Ventura
- Ed Schepis
- Fabrizio Gianneschi
- Luca Grulla
- Luigi Zanderighi
- Marcello Teodori
- Mida Boghetich
- Muralidharan Chandrasekaran
- Piero Ricca
- Renzo Borgatti
- Simone Bordet
- Simone Bruno
- Uberto Barbini
- Valvolog
- Webtide blogs (Greg Wilkins & Jan Bartel)
Links




















No Responses to “Execute commands in modified environment”
Please Wait
Leave a Reply