Question: I have a particular command, that reacts differently depending on the content of the current working directory.
I now wish to pipe this program back to itself, back have the call happen in different directories.

In "pseudo-bash", I want

```
command arg1 | cd /other dir | command arg2

```

I personally use bash, but if it helps to use a different shell, I'm open to suggestions. :)

I realize there is a very easy workaround with a temporary file or named pipe, but I want to know if there's a way to do this in one command.

Answer: 
```
command arg1 | ( cd /other_dir ; command arg2 )

```

`(…)` executes a command in a subshell. `cd` is a shell builtin command, not a 'real process'. `( cd X ; command )` will start a new sub-shell, cd into X, then run `command`. `command` is running as a process, but in a different directory.

Going forward it's better to have commands that can take a directory as an argument (and if not defined, default to the current working directory). Then you could have the simple solution of `command arg1 | command --dir=/other_dir arg2`
Pipes don't work that way. They are simply a way to pass data streams (*not context*) from one command to another. If you need a command in a pipeline to run in a different *context* from the others, you'll just have to change the directory in that [subshell](http://mywiki.wooledge.org/SubShell), as @JoachimPileborg pointed out.

The canonical way to solve this in \*nix shells is to instead pass the relevant directory as a parameter to the script. Your command sequence would then be:

```
command arg1 .
command arg2 /other/dir

```