Directory based environment variable scope - how to implement?

前端 未结 7 535
庸人自扰
庸人自扰 2021-02-04 00:03

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

7条回答
  •  无人共我
    2021-02-04 00:27

    This is not pretty, but you can use a combination of exported environment variables and the value of $PWD.

    For example:

    export VAR1=prefix
    export prefix${HOME////_}_foo=42
    export prefix${HOME////_}_bar=blah
    

    Then myscript needs only to eval echo \${$VAR1${PWD////_}} to get at the directory based value.

提交回复
热议问题