Run new zsh and bash shells with custom as command line agrument Run new zsh and bash shells with custom as command line agrument bash bash

Run new zsh and bash shells with custom as command line agrument


Create your own "shim" rcfile that's available to your users then call that with the --rcfile option (for bash) or --rcs option (for zsh). This should source the user's rcfile first. For example, let's call this /usr/local/share/.fancypromptrc. In bash this might look like:

source "$HOME/.bashrc"export PS1="DOLLAZ $"

And in zsh this might look like:

source "${ZDOTDIR:-$HOME}/.zshrc"export PS1="DOLLAZ $"

Then the user would start bash with bash --rcfile /usr/local/share/.fancypromptrc. In zsh it would be zsh --rcs /usr/local/share/.fancypromptrc.

This way the user doesn't have to modify their rcfile and if they are already setting PS1 it will still be replaced. The only time I can imagine this not working is if they have a PROMPT_COMMAND that overwrites the PS1, or something similar.


Anything you do from the command line is likely to be overridden by your configuration files. You'll need to modify the appropriate file slightly to use something like

# *After* you make any changes to PS1if [[ -n $MY_PS1 ]]; then    PS1=$MY_PS1fi

If you invoke the shell as

MY_PS1='yes master? > ' bash   # or zsh

then MY_PS1 will be used instead of whatever is configured in .{bash,zsh}rc.


I found the answer. We should just create a dir with custom config files, like .zshrc:

source $ZDOTDIR_ORIG/.zshrcexport PS1="[x] "$PS1

and then use a script to execute child shell remembering original value of ZDOTDIR var under ZDOTDIR_ORIG name, like this pseudopythoncode:

if os.environ.has_key('ZDOTDIR'):    zdotdir = os.environ['ZDOTDIR']else:    zdotdir = os.path.expanduser('~')os.environ["ZDOTDIR"] = shellConfPathos.environ["ZDOTDIR_ORIG"] = zdotdir

And then execute the shell. It will use the config file from ZDOTDIR directory.