Tag Info

New answers tagged

2

Inspired by Gnouc answer, I realized that bash reads /etc/bash.bashrc and ~/.bashrc in the same cases. Thus, you can put at the bottom of /etc/bash.bashrc: if [ -s "${XDG_CONFIG_HOME:-$HOME/.config}/bash/bashrc" ]; then . "${XDG_CONFIG_HOME:-$HOME/.config}/bash/bashrc" fi and then move ~/.bashrc to $XDG_CONFIG_HOME/bash/bashrc Bash will still ...


2

With a login shell, typically, your ~/.bash_profile contains the line: if [ -f ~/.bashrc ]; then . ~/.bashrc fi So you can set your own config folder here: BASHRC_CONFIG_DIR=~/config/bash if [ -f "$BASHRC_CONFIG_DIR/.bashrc" ]; then . "$BASHRC_CONFIG_DIR/.bashrc" fi For non-login shell, you can set it in /etc/bash.bashrc.


4

The bash command accepts a --rcfile filename option that will: Execute commands from filename (instead of ~/.bashrc) in an interactive shell. So if you run bash --rcfile ~/.config/bashrc then you will load that file instead. There isn't a way to configure it to load from there by default (where would you configure it?), other than recompiling it with ...


2

Try: PS1="\[\e[m\]$PS1\[\e[32m\]" trap 'printf "\e[m" > /dev/tty' DEBUG That sets the colour to green just after the prompt and back to the default just before each command is executed (and before the prompt). Note that commands can still change the colour of their output if they wish. You may prefer to use a shell with proper syntax highlighting ...


1

When you do: ssh serva -t "source ~/.bashrc" ssh tells sshd to invoke the login shell of the remote user as: the-shell -c 'source ~/.bashrc' That tells the-shell to run that command and exit. Probably, what you want is to run an interactive shell and have that interactive shell to run that source ~/.bashrc command and then to issue a prompt and read ...


0

bash --noprofile --norc <<ALIAS $(alias) exec </dev/tty ALIAS That should do it if you're running the bash --noprofile... bit from a bash that knows your aliases. Else you could do as @WilliamEverett suggests (which, as I believe, is ultimately the better way to go). One way to facilitate this is: alias >~/.aliasrc { cp ~/.bashrc ...


1

You could make your .bashrc more modular (for example by sourcing a .aliasrc with your aliases) and then have your custom environment only source the modules that you specify for that environment.


0

You could put if [ -f ~/.Mayur_Patel_special ] then . ~/.Mayur_Patel_special rm ~/.Mayur_Patel_special fi at the end of your .bashrc, and then have your application create that file.  And, obviously, run bash without the --noprofile and --norc options.  If there might be multiple instances of this running concurrently, make the filename unique; ...


0

/etc/bash.bashrc is read by interactive shells when they start up. It is a place for settings for interactive use, such as completion setup, prompts, etc. Do not set environment variables there. See Alternative to .bashrc Good places for system-wide environment variables are /etc/environment and /etc/profile (and files in /etc/profile.d). The normal Upstart ...


1

You can force bash to read /etc/bash.bashrc and ~/.bashrc (without the other side effects of using bash -i) by tricking it into thinking it's invoked over ssh: sudo -Hu someuser env SSH_CLIENT=1 SHLVL=0 \ "NODE_PATH=$NODE_PATH" "FULL_PATH=$FULL_PATH" \ "FILE_NAME=$FILE_NAME" "PROGRAM_NAME=$PROGRAM_NAME" bash -c ' "$NODE_PATH" "$FULL_PATH/$FILE_NAME" ...


0

You can force bash to be executed as interactive shell. Try this command: sudo -iu someuser /bin/bash -i -c '$NODE_PATH $FULL_PATH/$FILE_NAME \ >> /var/log/$PROGRAM_NAME.sys.log 2>&1' Now, before your command is executed, ~/.bashrc and /etc/bash.bashrc are sourced by bash. It's the same behavior as when you open a terminal.


3

The following should work: ssh $BUILDSERV "source ~/.bash_profile && cd $BUILDDIR && make && scp ./my_bin $TARGET" The source shell builtin reads a file and executed the commands in the same shell (unlike simply calling the script, which invokes a separate shell). When invoked as login shell, bash executes the .bash_profile, if it ...


1

As requested. The following should work [[ $(ps -ocommand= -p $PPID | awk '{print $1}') = script ]] || { script -f /var/log/shellog/$USER-$(date -u +%Y.%m.%d-%H:%M:%S).${HOSTNAME:-$(hostname)}.$$.log && exit ;}



Top 50 recent answers are included