Alex Rivera | Logout

How do I run a program with a different working directory from current, from Linux shell?

Asked 2009-04-24T15:36:23.337
434

Using a Linux shell, how do I start a program with a different working directory from the current working directory?

For example, I have a binary file helloworld that creates the file hello-world.txt in the current directory.

This file is inside of directory /a.

Currently, I am in the directory /b. I want to start my program running ../a/helloworld and get the hello-world.txt somewhere in a third directory /c.

Edit
Report

1 Answer

22
sh -c 'cd /c && ../a/helloworld'
answered 2009-04-24T15:49:37.550

Your Answer