Inside my .bashrc, I'm doing a bunch of magic that causes problems when I'm trying to do an scp. The solution I've been going with is to manually ssh to the target machine, disable my .bashrc, do the copy, and then re-enable my .bashrc. Is there a way to get around this?

  • 1
    Which OS? The answer depends on whether you are on Mac OS or any other *Nix – MariusMatutiae Dec 19 '13 at 17:34
  • This screams of XY problem. Please show us your .bashrc, explain what you are trying to do, and explain what problems you get. Also tell us the OSes on all machines involved. Especially if any of the are OSX since they have decided to make teh default shell a login shell so .bashrc is ignored. – terdon Dec 19 '13 at 17:37
  • What's happening in the .bashrc is largely irrelevant here. The point was that I just wanted to skip most of it if I was in scp instead of ssh, but I forgot about the non-interactive shell trick that Tourniquet pointed out in the accepted answer. That solved the issue. – Wesley Bland Dec 19 '13 at 18:27

My standard bashrc on debian had this as the first lines:

if [ -z "$PS1" ]; then

This checks if the variable $PS1 is set (which only is set if you're on an interactive shell), and prevents the execution of the rest if it isn't.

| improve this answer | |
  • Perfect. This is exactly what I was looking for. – Wesley Bland Dec 19 '13 at 18:25

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.