开发者

Is there a way to wrap arbitary commands located under a subdirctory in a shell script

I have a bunch of customizations and would like to run my test program in a pristine environment. Su开发者_Go百科re I could use a tiny shell script to wrap and pass of arguments but it would be cool and useful if I could invoke a pre and possibly post script only to commands located under certain sub directories. The shell I'm using is zsh.


I don't know what you include in your “pristine environment”.

If you want to isolate yourself from the whole system, then maybe chroot is what you're after. You can set up a complete new system, with its own /etc, /bin and so on, but sharing the kernel, networking and other non-filesystem stuff with your running system. Root's cooperation is required (the chroot system call is reserved to root).

If you want to isolate yourself from your dot files, run the program with a different value for the HOME environment variable:

HOME=~/test-environment /path/to/test-program
HOME=~/test-environment zsh

If this is specifically about zsh's configuration files, you can set the ZDOTDIR environment variable before starting it to tell zsh to run its own dot files from a directory other than $HOME (or zsh --no-rcs to not load any dot file).


If by pristine environment you mean a fully controlled set of environment variables, then the env program does this.

env -i PATH=$PATH HOME=$HOME program args

will run program args with only the environment variables you specified.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜