How can I debug the bash prompt? How can I debug the bash prompt? bash bash

How can I debug the bash prompt?


Most of the shells have debug flags that show the commands being executed. Bash may even have one that shows a command before expansion of variables and after. Have you tried checking (I believe) -c -x or -X flags and see if they show the information you are looking for.

You can set them as first thing in the rc files (most global one) or just pass it down into bash command by invoking it from another shell.

In fact, if you invoke bash from another shell, you can also use script command to record everything you see and do into the file, which makes postmortem analysis so much easier.


Try invoking bash with the -x flag, then sourcing your .bashrc or .bash_profile or whatever you're using. That ought to be prolix enough to find your problem

ie:

bash -xsource .bashrc


The easiest way to get a clean initial state is to SSH into your current host, but instead of letting SSH launch your shell with default settings, you provide an explicit command which prevents .bashrc from being read.

ssh -tt localhost /bin/bash --norc

The -tt forces SSH to allocate a TTY, which is what would normally happen when you open a shell connection, but is not default when running an explicit command.

The --norc prevents bash from reading your settings file (since we want to do that ourselves).

You should now be at a bash prompt, in a clean environment. This is useful for examining what variable are set to before your .bashrc runs etc. Enable tracing and source your .bashrc:

set -x   # Enable tracingsource .bashrc