2

My .bashrc file on my server is relatively simple, but it has this chunk to ensure that it automatically connects to tmux on login:

echo Checking for tmux
if [ -z ${TMUX} ]
then
      /usr/bin/tmux attach || /usr/bin/tmux
fi

This generally works fine, but when I try to scp to this server it doesn't work. I see the "Checking for tmux" message on my local terminal when I scp followed by "no sessions; not a terminal". To fix this I tried changing the test above to

if [ -z ${TMUX} ] && [ -t 0 ]

This gets rid of the "no sessions; not a terminal" error, but the files just silently don't copy. The copy works fine if I comment out the above entirely, so clearly the problem is with this, but I'm not sure why it would be affecting anything if it just fails the above test. What is happening?

1 Answer 1

2

You should not print anything in non-interactive shells. Typical code snipped for .bashrc is:

[[ $- != *i* ]] && return

in the beginning, which skips all file for non-interactive shells.

You should use this check in front of the echo, such as:

[ -t 0 ] && return
echo Checking for tmux

because the echoed text will break scp protocol.

You must log in to answer this question.

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