I’m trying to create a script that launches another script and have it as a child directly. My goals are:
- the child program should see a different $HOME
- the child script should run in a different directory than the current working directory (i.e. different pwd)
- no extra shells
I achieved the first two goals via subshells and exec, but I’ve yet to manage the third one. Could someone help me?
Here are the details. For ease of description, I will call the first script run, and the other program sleepcmd. Here’s the content of sleepcmd script
echo $HOME && exec sleep 1000
Here’s the content of run script
(HOME=~/foo/bar && cd $HOME/bin && ./sleepcmd)
Adding an exec before ./sleepcmd invocation, i.e.
(HOME=~/foo/bar && cd $HOME/bin && exec ./sleepcmd)
gets this to just one extra shell, compared with running sleepcmd (or sleep) directly.
How can I do better than that, and get rid of the () subshell, while still invoking sleep 1000 with a different $HOME and working directory?
try
e.g.