Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Ok, so I have used linux for a long time but this is the weirdest thing I have encountered in a long time. Maybe I just don't do a lot of scp so probably missing something simple here. So in my .bashrc file I have the following.

export KERNEL=$(uname -r)
#echo "HOST: $HOSTNAME: KERNEL VERSION: $KERNEL"
if [ $KERNEL == "2.6.32-431.3.1.el6.x86_64" ];then
   ... logic here
else
    .. more logic
fi

Now if I uncomment that echo line then the following command doesn't work! It just shows the echo but doesn't do any copying. If I remove that line it does the copy

$ scp -r host1.net:/prod/path1/path2/dir1/etc /tmp/user/sim/dir1
HOST: host1.net: KERNEL VERSION: 3.4.70-1.el6.companyX


$ scp -r host1.net:/prod/path1/path2/dir1/etc /tmp/user/sim/dir1

pybackup 100% 174 0.2KB/s 00:00
Proxy.ini 100% 623 0.6KB/s 00:00

This is strange...

share|improve this question
2  
I happened to find a good answer here: stackoverflow.com/a/12442753 – Spiff Mar 17 '14 at 17:32
    
thanks for this. Good to know I wasn't losing it :) – bjackfly Mar 17 '14 at 21:37

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 and this post for more discussion on this issue.

There's a few workarounds available, how to use echo in a scp-safe manner in .bashrc:

case $- in *i*) echo Hello World ; esac
tty >/dev/null && echo Hello World
if [ -t 1 ]; then echo Hello World ; fi
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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