I have a set of tools which I need to pass parameters depending on the project I\'m working on. I\'d like to be able to automatically set a couple of environment variables based
How about wrap your script with a function (the function can be placed either in your bash profile/bashrc file in the system ones to make available for all the users ).
myscript () { case $PWD in
/path/to/foo) path/to/myscript --var1=$VAR1 ;;
/path/to/bar) path/to/myscript --var2=$VAR1 ;;
*) ;;
case
}
Hence the function myscript will call the real "myscript" knowing what to do based on the current working directory.
Take this as an example:
hmontoliu@ulises:/tmp$ myscript () { case $PWD in /tmp) echo I\'m in tmp;; /var) echo I\'m in var;; *) echo I\'m neither in tmp nor in bar; esac; }
hmontoliu@ulises:/tmp$ myscript
I'm in tmp
hmontoliu@ulises:/tmp$ cd /var
hmontoliu@ulises:/var$ myscript
I'm in var
hmontoliu@ulises:/var$ cd /etc
hmontoliu@ulises:/etc$ myscript
I'm neither in tmp nor in bar