0

I want to load my personalized bash file ~/.bashrc.me instead of the one that is located at ~/.bashrc

I was hoping there was something to the effect of:

bash --dotfile=.bashrc.me

Does such a thing exist?

I'd rather not mess around with $SHELL, I find that inelegant and it might complicate my end goal (to do with ssh'ing into a shared machine and piping in my dotfile, but that's another question).

EDIT: To use a local dotfile in a remote SSH session, see this: https://superuser.com/a/1078431/114723

  • Why couldn't you just modify the .bashrc file to have your custom things in it? Unless you are using shared accounts it shouldn't affect other users. Also if you are connecting over ssh the .bashrc file may not be sourced at all since it's not an interactive session it may only source .bash_profile and .profile. – Jesse_b Jul 14 '17 at 20:58
  • 1
    If Michael's solution doesn't work for you, this thread may have some useful tips for you: serverfault.com/questions/164196/… – Jesse_b Jul 14 '17 at 21:00
  • Like you said, it's a shared machine with a single account and other colleagues won't like some of my customizations (e.g. the prompt, colors). – user7000 Jul 14 '17 at 21:01
  • 1
    One thing I've done in the past on remote shared machines is to add a check to .bashrc looking at $SSH_CONNECTION, and if the connection is coming from my local workstation, source my config file. Similarly with a shared root account, if you get a root shell with sudo -i, you can use the $SUDO_USER to set up a custom per-user config. – camh Jul 15 '17 at 0:24
3

--init-file:

--init-file filename

--rcfile filename

Execute commands from filename (instead of ~/.bashrc) in an interactive shell.

  • Perfect! Now I don't have to type source .bashrc.me every time (which often I'm too lazy to do). – user7000 Jul 14 '17 at 21:03
  • 1
    Would this look for the file on the local machine or remote machine? So if I did: ssh jbutryn@hostname < bash --rcfile /path/to/file /path/to/script . would it pull both the script and rcfile from the local machine before sshing to the remote machine? – Jesse_b Jul 14 '17 at 21:07
  • The remote machine can't read your files (but that command is ill-formed anyway). – Michael Homer Jul 14 '17 at 21:08
  • 1
    Yea it doesn't work but if you do ssh user@machine < /local/path/to/script the local script will be executed against the remote machine. – Jesse_b Jul 14 '17 at 21:15
  • There must be a way to get that to work but I can't figure it out either. Maybe a here document would help.unix.stackexchange.com/questions/187960/… – user7000 Jul 14 '17 at 21:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.