We have env(1) to modify the environment of the command we want to run (for example env MANPAGER=more man dtrace
). Is there something similar but for modifying the directory that the command is going to be started in?
Ideally, I would like it to look like this:
theMagicCommand /new/cwd myProgram
This way it could be "chained" with other env(1)-like commands, e.g.,
daemon -p /tmp/pid env VAR=value theMagicCommand /new/cwd myProgram
So far I can think of the following solution, which unfortunately does not have the same interface as env(1):
cd /new/cwd && myProgram
Also, I can just create a simple shell script like this:
#! /bin/sh -
cd "${1:?Missing the new working directory}" || exit 1
shift
exec "${@:?Missing the command to run}"
but I am looking for something that already exists (at least on macOS and FreeBSD).
myProgram
is not necessarily a desktop application (in which case I could just use the Path key in a .desktop file).
cd /new/cwd && env VAR=value myProgram
not meet your critera? – jpaugh Nov 09 '18 at 19:27env
. Look atenv
. Compare it tortprio
,idprio
,numactl
,jexec
,chrt
, and indeed the commands in the toolsets mentioned in the answers. There's a pattern, and it is chain loading. – JdeBP Nov 10 '18 at 00:08(cd the/cwd; cmd)
? – Konrad Rudolph Nov 10 '18 at 10:16(cd the/cwd; cmd)
to env(1) without wrapping it with sh(1). – Mateusz Piotrowski Nov 10 '18 at 20:41