如何利用eclipse+basheclipse+ShellEd构建bash shell 可视化debug环境--(1)

10 篇文章 0 订阅
3 篇文章 0 订阅

How to use eclipse+basheclipse+ShellEd construct a environment for graphic debugging bash shell script .

写在前面:

我打算同样的标题,写两遍内容。

第一遍从纯技术角度描述内容,第二遍剖析如何从系统哲学的角度客观地,机械化地分析这个过程。

多年来我主要的工作,是在windows平台开,开发C++,MFC,VB,dotnet等等的开发工作,特别是人机界面啊,自动化等等。

Linux下开发的经验当然也有,但没这么专业搞过。

最近需要研究一个相对复杂的脚本,对我来说还是相当有难度。

所以,想单步跟一下,看看究竟。

所以,到网上找了一些资料。

https://unix.stackexchange.com/questions/131491/is-there-a-gui-debugger-for-shell-scripts

文章写得很详细。

最重要的几个坑,这里我列一下:

(一)basheclipse+ShellEd这是两个不同的插件。一个是为了与bash联系用的。一个是用来语法高亮的。而且,这两个插件的安装方法不同。一个是解压后,拷到plugins里面即可。另一个是Help -> Install new software -> Add -> Archive。

(二)basheclipse有十几年没有人维护了。所以,eclipse4.0 以上,不能用。我从网上下了3.8的可以的。

链接过后我补上。

(三)bash的版本需要在4.0以上。bash -version .我的本机是 ubuntu18.04,是这个版本以上。不过,ubuntu 18.04 不太好用,不建议大家安装。经过这段时间接触,看来还是老牌子的Cent OS更靠谱。当然,有钱还是Redhat更好了。

(四)这是一个比较大的坑,需要在eclipse中,将默认的dash换也bash。

上面的链接里面有。

(五)然后就是建工程,填加脚本。注意将这句,放到最开始:. _DEBUG.sh (注意点后有空格,等价于source,类似C语言里的include)。然后,是启动的过程。这个过程,eclipse的菜单里没有,需要右键要调试的shell script文件。

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

下断点也是个小坑,实际上双击下断也可。eclipse其本上就是个将就用的货,你知道,而且关键是他不确定性很强。和野比康夫他们家那个时空抽屉差不了多少:它想让你去哪,你就去哪。

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. 

最后,要在需要debug的.sh上面,右键启动,不要从菜单或工具条启动。

明天我把图贴上。

===============原文============================

Debugging bash scripts on command line is complicated.

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

bash shell shell-script debugging

7

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


shareimprove this answer
edited Mar 19 '18 at 7:10

===========================

我补充的图:

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值