Using echo in a .bashrc will break scp, as scp expects to see its protocol data over the stdin/stdout channels. See https://bugzilla.redhat.com/show_bug.cgi?id=20527 for more discussion on this issue.
There’s a few workarounds available:
- Condition on the ‘interactive’ flag (e.g.
case $- in *i*as suggested by tripleee) - Use the
ttyutility to detect an interactive shell (e.g.if tty > /dev/nullorif [ -t 0 ]) - Check the value of
$SSH_TTY
I suppose you should use whichever one works for you. I don’t know what the best (most portable/most reliable) option is, unfortunately.