Can I tell if I'm in an scp session in my .bashrc?

6

1

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?

Wesley Bland

Posted 2013-12-19T17:32:04.040

Reputation: 315

1Which OS? The answer depends on whether you are on Mac OS or any other *Nix – MariusMatutiae – 2013-12-19T17:34:43.487

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 – 2013-12-19T17:37:42.960

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 – 2013-12-19T18:27:20.443

Answers

13

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.

tourn

Posted 2013-12-19T17:32:04.040

Reputation: 256

Perfect. This is exactly what I was looking for. – Wesley Bland – 2013-12-19T18:25:11.933