Is it possible to debug bash scripts line-by-line? - bash

I'll love something like Microsoft Visual Studio's line-by-line debugging in bash, with current variables values and so.
Is there any tool or way to do it? set -x and set -v are nice but not perfect.

See bashdb.
If it's installed on your system, see man bashdb.
If it's not installed, see http://bashdb.sourceforge.net

Yes. Use "bashdb" from http://bashdb.sourceforge.net/
Latest version at time of writing
http://sourceforge.net/projects/bashdb/files/bashdb/4.2-0.8/
If you are on a Mac (like I was) then you might need to install the GNU version of Bash.
I did that using "MacPorts"
http://www.macports.org/
Once you have MacPorts...
port install bash
Then follow the instructions to
./configure (in bashdb unpacked directory)
make
sudo make install
Then add the folder where bashdb can be found in your PATH

Related

Why Ocaml version located on file (4.04.0) different from what terminal says (4.03.0)?

I've been trying to run a program that uses graphics (which I've already posted about here). This post and other posts have led me to the conclusion that I need create a ~/.bashrc and put in it:
alias ocaml="/usr/local/Cellar/ocaml/4.03.0/bin/ocaml”
However, /usr/local/Cellar/ocaml/4.03.0/bin/ocaml is not a valid file in my system. B/c when I ran this in the terminal:
$ cd /usr/local/Cellar/ocaml/4.03.0/bin
-bash: cd: /usr/local/Cellar/ocaml/4.03.0/bin: No such file or directory
But changing the version to 4.04.0 works:
$ cd /usr/local/Cellar/ocaml/4.04.0/bin
But when I ask the terminal what ocaml I'm running:
$ which ocaml
/Users/Username/.opam/4.03.0/bin/ocaml
It says I'm running 4.03.0
And my error message when I try to run an ocaml program using graphics is :
Error: Cannot find file /Users/Username/.opam/4.03.0/lib/ocaml/graphics.cma
So it seems like my terminal is running 4.03.0 but I don't have OCaml 4.03.0 in /usr/local/Cellar/ocaml/4.03.0/bin and instead I have 4.04.0??
That to me seems very strange.
If anyone could please help me out that would be greatly appreciated! I have spent hours trying to figure out how to run graphics on my computer and I have no clue why the solutions posted in previous StackOverflow posts are not helping :(
i don't find it strange.
The alias command works only in your terminal, not for the entire system.
Probably you have "/Users/Username/.opam/4.03.0/bin/ocaml" in your PATH variable.
I suggest to do:
export PATH="/usr/local/Cellar/ocaml/4.04.0/bin:$PATH"
then:
which ocaml
and the path should be the 4.04 version
It looks like that you have multiple installations of OCaml on your machine. Some of them being installed via opam, and others either manually, or via system package management. I would suggest just to ignore the latter and focus on opam.
To use opam, you need to activate your switch. This can be done manually,
eval `opam config env`
(Note the use of backticks)
You can also put it in your profile, so that opam will be activated every time you logged in. You can even ask opam to do it for you:
opam config setup --user
Finally, if you want to run a program, out of your normal terminal environment, and do not want to depend on some pre-setup steps (i.e., on a client's machine), then you can use opam config exec:
opam config exec -- ocaml my-ocaml-script.ml

cygwin bash not returning a valid result

I am following this :
Step 2: Installing Cygwin
Cygwin can be downloaded from http://www.cygwin.com
Run the setup file.
Install from internet. Specify C:\cygwin as the root directory.
In the Select Packages dialog box, select the packages required. gcc-core, gcc-g++, gdb, and make packages are most important. These are the C core, C++ core, the GNU Debugger and the GNU version of ‘make’ utility. These packages will be under the ‘Devel’ category.
Complete the installation.
Step 3: Testing Cygwin
To test whether Cygwin was installed properly, try the following by opening the bash shell:
cygcheck -c cygwin
gcc --version
g++ --version
make --version
gdb --version
If the version details are displayed for all these commands, the installation of Cygwin has been successful.
I got this from here
But the result I get is:
What is wrong or missing with my installation.
Follow up question:
I wanted to use the terminal window in netbeans that is why I installed this.
In this terminal widnow I also have problem. I cant type anything on it. Is this the reason for it?
Try to run /usr/bin/g++. If it is not found, then you don't have g++ installed (installation may have had problems).
You can follow the same procedure for the rest of your commands
If /usr/bin/g++ runs successfully, it means you don't have /usr/bin in your PATH (which is very unlikely). You can put that in your PATH in your startup file.

Download different version of grep in cygwin?

I'd like to download a different version of grep in Cygwin. Currently, I have version 2.21, but I'd like to get version 2.5.1 (this is what runs on Mac OS by default, and I'm more familiar with that).
I obviously don't want to run the entire setup again. Is there a way to get the Mac OS version (i.e. 2.5.1) without running setup all over again? Thanks. <3
Compiling is always a possible choice: grep lives here: ftp://ftp.gnu.org/gnu/grep/, and given the tarball (ftp://ftp.gnu.org/gnu/grep/grep-2.5.1.tar.gz),
tar xf 2.5.1.tar.gz
cd 2.5.1
./configure
make && make install
(this will probably install into /usr/local/bin — you should read the instructions, e.g., the --prefix option to suit your own needs).
That assumes you are developing, and have installed gcc (the Cygwin setup program helps in that case).

how can I run shell script line by line [duplicate]

I'll love something like Microsoft Visual Studio's line-by-line debugging in bash, with current variables values and so.
Is there any tool or way to do it? set -x and set -v are nice but not perfect.
See bashdb.
If it's installed on your system, see man bashdb.
If it's not installed, see http://bashdb.sourceforge.net
Yes. Use "bashdb" from http://bashdb.sourceforge.net/
Latest version at time of writing
http://sourceforge.net/projects/bashdb/files/bashdb/4.2-0.8/
If you are on a Mac (like I was) then you might need to install the GNU version of Bash.
I did that using "MacPorts"
http://www.macports.org/
Once you have MacPorts...
port install bash
Then follow the instructions to
./configure (in bashdb unpacked directory)
make
sudo make install
Then add the folder where bashdb can be found in your PATH

Trouble trying to install MIT-Scheme on MacOSX Snow Leopard

I am trying to install MIT-Scheme so that i can use it off my terminal instead of using an IDE, however, I am having difficulty trying to find tutorials that are actually up to date and works.
You can install MIT Scheme through Macports, and it will probably take a long time (it's compiling it from source, I think). You can also get a precompiled binary from here which will install an MIT-Scheme.app which starts Edwin an Emacs port or something which includes a Scheme debugger and REPL. But you can also start it from the command line.
Check to see where it installed to, on my machine it's here /Applications/mit-scheme.app/Contents/Resources/ but that might vary. Add this directory to your PATH by editing ~/.bash_profile and adding this:
export PATH=$PATH":/Applications/mit-scheme.app/Contents/Resources/"
Check with which mit-scheme to make sure it installed correctly.
As for Racket, there's also a precompiled binary available from here. (It might be in Macports but it might not be, or in Fink, I don't know. I try to avoid those and use Homebrew if possible.) This is a dmg file which you can extract and put wherever you want. I put mine in ~/bin and added ~/bin/racket/bin/ to my PATH as well, same process as above, but you can put it anywhere, /Applications/ or whatever.
Good luck.
This seems like a odd answer since it's about Racket for a question that was originally about MIT Scheme, but since you tried Racket too...
To run Racket from the terminal, you need to use the racket executable, which is found in the bin subdirectory. For example, if you install it at /Applications/Racket-5.1, then you'd run /Applications/Racket-5.1/bin/racket. (And you could modify your $PATH or add some symlink to make it possible to run without specifying the full path.)
You can find the detailed answer here.
Here is a short version:
Download .dmg file of MIT-Scheme. 32-bit or 64-bit based on your hardware architecture.
After installation run the following commands
For 32-bit package:
sudo ln -s /Applications/MIT\:GNU\ Scheme.app/Contents/Resources /usr/local/lib/mit-scheme-i386
sudo ln -s /usr/local/lib/mit-scheme-i386/mit-scheme /usr/bin/scheme
For 64-bit package:
sudo ln -s /Applications/MIT\:GNU\ Scheme.app/Contents/Resources /usr/local/lib/mit-scheme-x86-64
sudo ln -s /usr/local/lib/mit-scheme-x86-64/mit-scheme /usr/bin/scheme
To run MIT-Scheme from your terminal just type 'scheme' in the command prompt.

Resources