Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I debug the bash prompt?

I've been editing .bashrc files and other init files, and it seems that I've left behind a few code snippets or two that are causing a few errors at the prompt (e.g. file missing), but I can't find them.

How do I debug the prompt to find out what init scripts I've carelessly hacked?

like image 729
fny Avatar asked Nov 24 '11 19:11

fny


People also ask

How do I debug Bash?

The debugging options available in the Bash shell can be switched on and off in multiple ways. Within scripts, we can either use the set command or add an option to the shebang line. However, another approach is to explicitly specify the debugging options in the command-line while executing the script.

Is there a Bash debugger?

The Bash Debugger Project is a source-code debugger for bash that follows the gdb command syntax. There are plugins available for VSCode and JetBrains. Also, there are POSIX shell debuggers for Zsh and the Korn Shell.

How do I enable debugging in command prompt?

To activate the debugger at the command prompt In the Session List window, do one of the following: Choose Debug Next. The debugger is now active and is waiting to attach to a session. Select a session, and then choose Debug.


2 Answers

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 -x
source .bashrc
like image 167
choad rocker Avatar answered Oct 04 '22 01:10

choad rocker


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.

like image 24
Alexandre Rafalovitch Avatar answered Oct 04 '22 01:10

Alexandre Rafalovitch