Sunday, 15 August 2010

bash - can I have the PATH variable evaluate to what directory I'm in? -



bash - can I have the PATH variable evaluate to what directory I'm in? -

on linux using bash, lets made 2 programs both called print_report. (they in different directories.)

inside .bashrc file, have:

path="path/to/print_report1/:$path"

this allows me type print_report anywhere , run 1 of programs.

how can have bash decide utilize 1 or other depending on working directory?

for example, if i'm in ~/project1/ , type print_report utilize /bin/foo/print_report if i'm in ~/project2/ , type print_report utilize /bin/bar/print_report

you can't such. instead, write wrapper script or function checks current directory , invokes right command:

#!/bin/bash if [[ $pwd == $home/project1/* ]] /bin/foo/print_report "$@" elif [[ $pwd == $home/project2/* ]] /bin/bar/print_report "$@" else echo "don't know how print_report $pwd" fi

bash shell path command-line-interface

No comments:

Post a Comment