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
up vote 13 down vote accepted

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

if [ -z "$PS1" ]; then
   return
fi

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.

  • 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 acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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