Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a GUI debugger for shell scripts

Debugging bash scripts on command line is complicated.

Is there a good GUI based debugger available for debugging bash scripts?

like image 680
Kshitiz Sharma Avatar asked May 22 '14 10:05

Kshitiz Sharma


People also ask

Can I debug a shell script?

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.

Which command is used to debug shell scripting?

Use of set builtin command Bash shell offers debugging options which can be turn on or off using the set command: set -x : Display commands and their arguments as they are executed.

Does bash have a GUI?

In fact, you are able to include GUI (Graphical User Interface) based input/output components into your next bash script using the Zenity command line tool which helps us to display GTK dialog boxes.


2 Answers

Download ShellEd eclipse plugin (update site didn't work for me) which allows editing bash scripts. Install this via Help -> Install new software -> Add -> Archive.

Download basheclipse and extract the contents to your eclipse plugins directory plugin.

Restart eclipse. Create a new Eclipse project BashTest.

Add a file myscript.sh to the project:

#! /bin/bash

. _DEBUG.sh

echo 'kshitiz'
echo 'This is a test'
x=1
y=3
z=3

Add _DEBUG.sh to your project (Its in the downloaded zip for basheclipse).

Go to Run -> Debug configurations and create a new configuration under Bash script category. Select myscript.sh.

enter image description here

Then click Debug. Open Debug perspective.

Go to Window -> Preferences -> Shell script -> Interpreters and ensure that interpreter is /bin/bash. For me the default was /bin/dash.

enter image description here

Set a breakpoint in the script. For some reason the right click menu does not show the option to set the breakpoint but Ctrl+Shift+B should work. enter image description here

Run the script Run -> Run as -> Run shell script. The breakpoint will hit but it won't be able to find your script source (wierd eh!). Just click Select Bash script and select myscript.sh.

Now you can step through the code and analyze the variables: enter image description here

like image 158
Kshitiz Sharma Avatar answered Oct 19 '22 06:10

Kshitiz Sharma


A useful trick is to start your (executable) bash script with

#!/bin/bash -vx

at least during the debugging phase; you'll get a lot of helpful messages from bash. See bash(1)

If your script is not supposed to be used in a terminal (e.g. it is invoked from a crontab(5) entry) you could also use the logger(1) command.

At last, I believe that bash is not the right tool to do complex scripting. If your script is becoming complex or bigger than a few dozens of lines, consider switching to a better scripting language (like GNU guile, python, gawk, etc...). In general, you should not code a lot in bash. Having pain to debug a bash script is usually a symptom that you should recode that script in a better language.

You may also find useful to generate your shell script. autogen could be useful for that.

like image 4
Basile Starynkevitch Avatar answered Oct 19 '22 06:10

Basile Starynkevitch