how can I run shell script line by line [duplicate] - 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

Using Bash insteal of Perl? (bashrc)

I was using a bash script in my bashrc and until now everything worked.
Today, i decided to install Perl on my computer (since I'm looking to learn the language) using the method on the website learn.pearl
curl -L xrl.us/installperlnix | bash
(urls are not accepted )
The problem is that now, my script doesn't work anymore, I'm having the error:
"no such file
export PERLBREW_BASHRC_VERSION=0.78"
I tried to use the command "perlbrew switch-off" but it seems that I don't have the program perlbrew installed, and my bashrc is starting with #!/bin/bash so I'm completely lost on you to fix the problem.
I would appreciate some help.
Thanks !
Make sure that you got everything to download the perlbrew, like curl or wget, it is simple to check, try one of theses:
which curl
which wget
If you have one of them you are able to download, otherwise you will need to install either curl or wget.
The latest realease of perlbrew is 0.78.
After theses first steps try to download it again as you did.
There is a mini tutorial which you can use as a guide:
https://perlbrew.pl/
Also I am not sure if you have it installed so you could use:
which perlbrew
To find out if you have it or not. Maybe you forgot the step as describe in the perlbrew site:
sudo cpan App::perlbrew
perlbrew init
Because it seems like your environment was not set yet.

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

How do I install Git for Windows software to a specific directory?

I have just downloaded the latest Git for Windows installer, v2.4. It appears to want to install to the standard Windows "Program files" (with-spaces-in-name) directory.
Since I have all my development code in a folder called (simply) "/bin" -- I want to see if there's a command line option or parameter to change the install directory.
In my case, these days I use a environment variable such as GIT_HOME for important software like git; so it would be useful if there was a way to apply that to things like git commands, etc once I have the program installed.
possibly related:
How do I change the directory in Git Bash with Git for Windows?
I also came across a few questions asking: "whereis git". That's answered above, however I take that as an indicator that others may want git somewhere else too.
To start the installer with a different installation path you can open a CMD terminal in the same directory as the installer executable and pass in an option parameter of /DIR="x:\dirname"
For instance, if you have version 2.17.0 for Windows 64bit and you want to install git to D:\git, you would run:
Git-2.17.0-64-bit.exe /DIR="D:\git"
The installer will launch as usual and you need to walk through the other options, but the install location will be the path specified.
Since I just ran into this problem because my SSD is filling up, I figured I'd share the solution I came to on Windows 11 with Git v. 2.37.2.
The best way I could figure was to uninstall Git, then in CMD Prompt use the suggested command from the Git website with an appended --location/ -l flag:
winget install --id Git.Git -e --source winget --location [drive:/directory]
where [drive:/directory] is your target for the install. Had no issues and verified it worked with a project.

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).

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

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

Resources