Skip to main content
Add \n since $() strips the last one.
Source Link
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''%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''%s\n' ' . ~/.bashrc alias ll=\"ls -l\" ' ) " 

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' '$( 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 just a few aliases or something inline to the remote ~/.bashrc:

ssh -t remote.example.com " exec bash --rcfile <( printf '%s' ' . ~/.bashrc alias ll=\"ls -l\" ' ) " 

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\" ' ) " 
deleted 221 characters in body
Source Link
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' '$( 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. From the bash manpage:

Enclosing characters in single quotes preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash.

We can safely quote bash-code by surrounding it with ', and substituting inner 's for '\''s.

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

ssh -t remote.example.com " exec bash --rcfile <( printf '%s' ' . ~/.bashrc alias ll=\"ls -l\" ' ) " 

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' '$( 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. From the bash manpage:

Enclosing characters in single quotes preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash.

We can safely quote bash-code by surrounding it with ', and substituting inner 's for '\''s.

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

ssh -t remote.example.com " exec bash --rcfile <( printf '%s' ' . ~/.bashrc alias ll=\"ls -l\" ' ) " 

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' '$( 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 just a few aliases or something inline to the remote ~/.bashrc:

ssh -t remote.example.com " exec bash --rcfile <( printf '%s' ' . ~/.bashrc alias ll=\"ls -l\" ' ) " 
[Edit removed during grace period]
Source Link
JoL
  • 5k
  • 1
  • 20
  • 37
added 265 characters in body
Source Link
JoL
  • 5k
  • 1
  • 20
  • 37
Loading
Source Link
JoL
  • 5k
  • 1
  • 20
  • 37
Loading