Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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

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
up vote 2 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

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

.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... – kstratis Jul 14 '12 at 23:59
One could argue that, but it all depends on how WinSCP uses the SSH protocol. – Fran Jul 15 '12 at 0:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .