Skip to main content
5 of 5
Add \n since $() strips the last one.
JoL
  • 5k
  • 1
  • 20
  • 37

A solution based on Gilles's that doesn't require adding AcceptEnv on the server for LC_XXX:

ssh -t remote.example.com " exec bash --rcfile <( printf '%s\n' '$( sed "s:':'\\\\'':g" ~/.bashrc )' ) " 

That's to use your local ~/.bashrc in the remote session. It takes advantage of the fact that everything in between single-quotes in bash is taken literally, so the only thing we need to worry about escaping are the inner single quotes themselves. We can safely quote bash-code by surrounding it with ', and substituting inner 's for '\''s.

If you want to add just a few aliases or something inline to the remote ~/.bashrc:

ssh -t remote.example.com " exec bash --rcfile <( printf '%s\n' ' . ~/.bashrc alias ll=\"ls -l\" ' ) " 
JoL
  • 5k
  • 1
  • 20
  • 37