Problem running .sh scripts on windows

Hi all,

I have been using an older GMT version on Ubuntu for a couple of years and thought it would be cool to try and run the latest gmt version on windows.

I have downloaded and run the installer for gmt6 and seems to have successfully installed gmt6 under C/programs. All good so far, double clicking on bat files (the examples) they seem to run just fine.

I am used to running gmt scripts in a linux environment so I downloaded and installed mingw64 and msys2 which from what I’ve read will allow me to run the scripts like in linux (I’m not very good with these things). I have installed mingw64 and msys2 in C/Apps

The problem is, when I launch the msys terminal, then navigate to the gmt directory and type “./ex03.sh” it will spit out several times:

$ ./ex03.sh
./ex03.sh: line 21: gmt: command not found
./ex03.sh: line 22: gmt: command not found
./ex03.sh: line 25: gmt: command not found
./ex03.sh: line 26: gmt: command not found
./ex03.sh: line 31: gmt: command not found
./ex03.sh: line 32: gmt: command not found
./ex03.sh: line 33: gmt: command not found
./ex03.sh: line 35: gmt: command not found
./ex03.sh: line 37: gmt: command not found
./ex03.sh: line 41: gmt: command not found
./ex03.sh: line 41: gmt: command not found
./ex03.sh: line 44: gmt: command not found
./ex03.sh: line 44: gmt: command not found
./ex03.sh: line 46: gmt: command not found
./ex03.sh: line 47: gmt: command not found
./ex03.sh: line 48: gmt: command not found
./ex03.sh: line 49: gmt: command not found
./ex03.sh: line 50: gmt: command not found
./ex03.sh: line 51: gmt: command not found
./ex03.sh: line 52: gmt: command not found
./ex03.sh: line 53: gmt: command not found
./ex03.sh: line 54: gmt: command not found
./ex03.sh: line 55: gmt: command not found

It’s like it doesn’t recognise gmt as a program at all. It’s clearly reading the file.
I did some more digging and I see some suggestions about adding the path under System>advanced system settings>Edit Environment variables but I see gmt is already there as c:\programs\gmt6\bin and this seems correct (?)

What’s going on, why doesn’t it recognise gmt commands? Is it looking in the wrong place?

Check out https://docs.generic-mapping-tools.org/6.0/migrating.html and decide on a course of action.

Thanks for the quick reply Paul. Unfortunately I’m stumped. Navigating to tools and running the script says:

./gmt_links.sh: line 28: gmt: command not found
./gmt_links.sh: line 31: gmt: command not found
Link for module minmax: Absent
Link for module gmt2rgb: Absent
Link for module gmtstitch: Absent
Link for module gmtdp: Absent
Link for module grdreformat: Absent
Link for module ps2raster: Absent

Then tried ./‘gmt_links.sh’ create

and got:

./gmt_links.sh: line 28: gmt: command not found
./gmt_links.sh: line 31: gmt: command not found
ln: failed to create symbolic link ‘minmax’: No such file or directory
ln: failed to create symbolic link ‘gmt2rgb’: No such file or directory
ln: failed to create symbolic link ‘gmtstitch’: No such file or directory
ln: failed to create symbolic link ‘gmtdp’: No such file or directory
ln: failed to create symbolic link ‘grdreformat’: No such file or directory
ln: failed to create symbolic link ‘ps2raster’: No such file or directory

even just typing gmt --version in the terminal yields nothing. I must have done something fundamentally wrong. Was I not meant to install from the windows executable if I’m planning to run it with msys? Am I meant to install it some other way?

I don’t know anything about msys etc, but sounds like you need to add the installation path for gmt to your PATH setting. It cannot find gmt and hence nothing can work.

I think the problem is that bash, like some others, is very picky and wants that your shell scripts have the executable mode set on.
The Github bash is less picky.

Thank you both but the problem persists. I have checked my environment variables and gmt is definitely among them (paths)

I tried chmod 777 as well as chmod +x to make script executable but made no difference

I’ll do some reading on environment variables because right now I have no idea what I’m doing

Sounds like just installing git for windows which comes with bash is the best solution than futzing around with mingw etc.

Yes. But as a last attempt try changing the shell script to Unix EOL

I know we are one year down the line but Jesus this git for windows just…worked. I don’t know why I didn’t do this at the time. I had spent days and days mucking around. Thanks Paul

1 Like