Tag Info

New answers tagged


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 ...


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.


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; ...


/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 ...


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" ...


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.


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 ...


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 ;}


Just put the script in a directory that is already in your path. It is for example quite standard to have /usr/local/bin in PATH, so you could add your script to /usr/local/bin. if you don't have permission, then adding the scripts location to your path is your other option.


Add the folder where the script is to your PATH? Use the full path to the script?


It won't source that file by default. You can direct it to do so: ENV=~/.shrc sh Or you might add: alias sh="PS1='\$0\$ ' sh" To your usual shell's environment file. It could simplify things. Or even: alias sh='ENV=~/.shrc sh' Still, if you only want to declare the one variable for it, explicitly setting $PS1 on the command line like in the first ...


Ok, so if you want to start tmux only when it exists in $PATH and when it isn't already running then you can do: command -v tmux >/dev/null && ${TMUX+:} TERM=xterm-256color exec tmux Shorter still: tmux -c "${TMUX+!} :" 2>/dev/null && exec tmux -2 The second one asks tmux to return 0 if ${TMUX} is not set && if true, the ...


Did you do echo $TMUX, while in a tmux session? Because TMUX is only set, when in a session. Try that instead: [ -z "$TMUX" ] && command -v tmux >/dev/null && TERM=xterm-256color exec tmux


You can almost definitely just do: alias >>./bash_aliases


Easy trick for alias in $(compgen -a); do type $alias; done


Why are the SSH variables set? It is likely that the variables are set because your VNC connection is tunneled through an SSH connection. There are good reasons to do this. VNC uses the RFB protocol which is not secure. Tunneling VNC through SSH improves security. Why is the SSH_CONNECTION variable the same? The SSH_CONNECTION variable consists of four ...

Top 50 recent answers are included