1

SHORT: How do I explicitly set the current working directory?

LONG: So I have 52 programs daisy chained together. I have a shell script pipeline that works great. Only problem is I can only run it if I cd into the directory with the files and run it. Some of the sub-programs do not have a mechanism that allows me to explicitly set output directories. They dump everything into the current working directory. This is fine if you are running 1 instance of this pipeline, but not so great if you are trying to process a dozen data-sets one after another. I know I can get the current working directory with:

echo $PWD

But how do I set it?

4

1 に答える 1

0

次のように、パイプライン内の他のプログラムに影響を与えることなく、パイプライン内の個々のプログラムの現在のディレクトリを設定できます。

PWD=path1 command1 && PWD=path2 command2

一般に、その構文を使用して任意の環境変数を設定できます。これは私がbashで試した実際の例です:

$ PWD=/home ./test.rb && PWD=/ ./test.rb 
Running in /home
Running in /
于 2016-12-27T18:25:41.677 に答える