Bash: How to only do things in interactive shells

Posted . Visible to the public.

When you print something from within your .bashrc file you will run into trouble when copying something onto your machine using scp for example.

This is because the output from your .bashrc interferes with scp. The solution is to decide whether the bash shell is started interactively (you start a terminal on your screen) or not (scp).

if [ ! -z "$PS1" ]; then
  # This happens in interactive shells only and does not interfere with scp.
  echo "Learn!"
fi
Thomas Eisenbarth
Last edit
License
Source code in this card is licensed under the MIT License.
Posted by Thomas Eisenbarth to makandra dev (2013-12-06 10:05)