Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I regularly use WinSCP to tranfer a few files to my personal server. However I recently experienced the infamous "bad packet length" error due to one of my echo statements residing inside the .bashrc file. Therefore with respect to this: sftp corruption error I would like to ask the following:

Why did the system complained for an echo statement (or whatever is causing the error) residing within my .bashrc file and not my .bash_profile instead?

..if the sftp is some sort of subprocess spawned by the ssh server as the above link suggests, shouldn't it first parse the .bash_profile file and complain about its own echo statements?

Thanks in advance

share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

I use the following line (two with comment) at the top of my .bashrc, it simply aborts if it isn't an interactive shell:

# if we're not an interactive shell, do nothing
[ -z "$PS1" ] && return

I suppose if you want the long form:

# if we're not an interactive shell, do nothing
if [ -z "$PS1" ]; then
    return
fi

This mitigates the need for a *.bashrc_profile* file, since the .bashrc changes how it responds based on how it was invoked.

share|improve this answer
add comment

.bash_profile executes for login shells. .bashrc executes for interactive shells. Apparently, WinSCP must be creating a non-login interactive shell on the remote machine. Details can be found in the INVOCATION section of the Bash man page.

share|improve this answer
    
Shouldn't WinSCP create a non-login non-interactive shell instead? I can't see how a session is considered interactive without a shell... –  Konos5 Jul 14 '12 at 23:59
1  
One could argue that, but it all depends on how WinSCP uses the SSH protocol. –  Fran Jul 15 '12 at 0:01
add comment

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.