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

Solution 1:

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.