Source .bashrc in zsh without printing any output
emulate -R ksh -c 'source ~/.bashrc'
This tells zsh to emulate ksh while it's loading .bashrc
, so it'll by and large apply ksh parsing rules. Zsh doesn't have a bash emulation mode, ksh is as close as it gets. Furthermore when a function defined in .bashrc
is executed, ksh emulation mode will be enabled during the evaluation of the function as well.
Hopefully this will solve the errors that you're getting when zsh reads your .bashrc
. If it doesn't, it should be easy to tweak your .bashrc
so that it works well under both shells for the most part. Make a few parts conditional, such as prompt settings and key bindings which are radically different.
if [[ -z $ZSH_VERSION ]]; then
bind …
PS1=…
fi
If you really want to hide all output, you can redirect it to /dev/null
(source ~/.bashrc >/dev/null 2>&1
), but I don't recommend it: you're just hiding errors that indicate that something isn't working, that doesn't make that thing work.
Related videos on Youtube
Zen
Updated on September 18, 2022Comments
-
Zen over 1 year
In the past, I've used bash consistently, because it's everywhere.
But recently I started to try zsh. I don't want to give up updating my.bashrc
fil which is rsync'ed to all my servers . So, in my.zshrc
, I sourced my old.bashrc
using the commandsource ~/.bashrc
.Everything goes well, except every time I open a new terminal window with zsh.
There is a bunch of information prompts to the screen. It looks like this:pms () { if [ -n "$1" ] then user="$1" else user="zen" fi python /Users/zen1/zen/pythonstudy/creation/project_manager/project_manager.py $user show "$2" } pmcki () { if [ -n "$1" ] then user="$1" else user="zen" fi python /Users/zen1/zen/pythonstudy/creation/project_manager/project_manager.py $user check_in "$2" } zen1@bogon:~|⇒
These are function definitions in my .bashrc. They're triggered by
source ~/.bashrc
in my.zshrc
file.What I want is for
.zshrc
to source my.bashrc
quietly, with all stderr and stdout output hidden.Is it possible to do that? How?
-
Admin almost 9 years
source ~/.bashrc > /dev/null 2>&1
? -
Admin almost 9 years@User112638726, brilliant, I saw similar stuff on the crontab task of my server... But this didn't come to my mind. Thank you!
-