Running gmt.script - bash

I try to run a gmt-script and get the message:
bash-3.2$ plot_scenario.gmt
bash: plot_scenario.gmt: command not found
Does anyone know what could fix the problem?
I got a script from my supervisor, and it worked just fine on the uni Linux pc.
I have a Mac OS.

When you type text in shell, it tries to look for available commands. Here bash doesn't find any command like plot_scenario.gmt and outputs command not found.
The proper way to execute a file is ./filename where . refers to current directory. But you need to give execution permission to file you want to run. So, following commands may help you:
chmod +x <filename>
./<filename>
Note that make sure your pwd is where you're file is located. Another way to run or execute file is calling the shell:
bash /path/to/file

Related

Cygwin execution of .sh file can't find grep command?

So I was trying to create little .sh script for my work and run into one little problem.
My cygwin terminal (x64) runs just fine and I'm using it often enough to do manual greps.
In the begging I had some issues with this command but now it works fine in cygwin terminal.
Once I wrote my little script and tried to run it only output I'm getting is "line 6: grep: command not found"
My execution method is:
Open cygwin terminal
cd to script location
type in ./script.sh
enter :)
Anyone knows how to fix that? I already added cygwin bin folder to my system path (Win 10 btw) but that didn't helped. Looked around for a while but haven't found anything useful, mostly issues with grep itself.
my script for reference:
mkdir -p output
PATH=$PWD"/output"
while IFS=";" read -r component location global
do
cd $location
grep -iRl $global --exclude-dir={wrongdir1,wrongdir2} > $PATH"/"$component".txt"
done < input.csv
you're overwriting you Cygwin system path: PATH=$PWD"/output" - instead of PATH use a diff var name.

Failing to run external Bash program — /usr/bin/bash: bad interpreter: No such file or directory

I'm trying to run a CLI tool in Linux (Mint) which allows me to edit subtitles. It is named subedit: github link. In order to run it, I've added executable permission with chmod +x and added it to the path in bash. However, when I run it, I get the following error message:
bash: /home/main/Documents/shellTools/subedit/subedit: /usr/bin/bash: bad interpreter: No such file or directory
I'm not very experienced with external bash programs and forgot to do something that would be obvious in hindsight.
When I do echo $PATH this is the output:
/home/main/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/main/Documents/shellTools/subedit/
Could somebody please help?
Assuming bash is installed, (it usually is), change the first line of subedit from:
#!/usr/bin/bash
to:
#!/bin/bash
Or if one would prefer not to edit subedit, try this one-liner covering what Al-waleed Shihadeh suggested:
ln -s "$(which bash)" /usr/bin/bash
It seems that you don't have bash installed, you can verify that by running
which bash
if the above command returns "bash not found", then you need to install it.
In case the above command returns a path, you can use the below command to add a symlink to the expected path
ln -s $(path from the above command) /usr/bin/bash
Use the command termux-chroot ONCE!
If you want to always run at the start of a session, be sure to check if it was never run before.
if [ -z $CHROOT ]; then
CHROOT=1
termux-chroot
fi

Raspbian: Reset Bash environment variables

I was trying to get a crontab working on my Raspberry PI and I think I messed up my environment variables. I can execute a file from the GUI by right-clicking and choosing execute. However I cannot get the same file to run from command line. I can use ls to see the file (ChromeTab.sh), but when I type ChromeTab.sh, I get "bash: ChromeTab.sh: command not found".
I think I messed up my environment variables when I put this in the crontab.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
I followed the examples in Script doesn't run via crontab but works fine standalone.
Any idea what I'm doing wrong?
UPDATE:
OK,
Let me clarify what efforts I took on my part BEFORE posting my question on stackoverflow before getting anymore downvotes.
First of all thanks S. Adam Nissley for your suggestions.
In answer to your steps listed above.
Running this from home path, or fully qualified path does Not work as stated.
Error: bash: ChromeTab.sh: command not found
./ChromeTab.sh
I have also ensured read/write and execute permissions on the file with
chmod +x ./ChromeTab.sh
Also, my bash script starts off with the following shebang
#!/bin/sh
So, what i'm trying to say is, regardless of using crontab or not the issue at hand is that I can not even execute the script from command line. This started happening after I was messing around with the environment variables in the crontab. I'm looking for a way to revert to the situation where I can at least run/execute bash commands from the terminal.
The only way I can effectively execute this script is (right-click execute) through the GUI.
Assuming you are in the same directory as your script, you should just be able to enter
./ChromeTab.sh
If it does not execute, make sure it is executable with the command
chmod +x ./ChromeTab.sh
Or
chmod 755 ./ChromeTab.sh
And if it still won't execute, make sure it has an appropriate hashbang on the very first line of the script like #!/bin/sh or #!/bin/bash
When you add it to your crontab, make sure it has the full path like
/home/pi/bin/ChromeTab.sh <br/>
EDIT: Default PATH and SHELL for Raspbian
You can check your PATH and SHELL environmental variables from the command line as follows:
echo $SHELL
echo $PATH
The default PATH for Rasbian is:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
And the default SHELL is:
/bin/bash
So if you need to set those it is as simple as:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
SHELL=/bin/bash
If you are having other issues with your environment, you may want to disable some of your local settings to see if the problem is in your profile. You can list all files with ls -a, which includes hidden files. Raspbian typically has a .bashrc and a .profile in each user's home directory. To disable them simple rename them:
mv .bashrc .bashrc_disabled
mv .profile .profile_disabled
If that solves the problem, you can inspect the files and make the necessary corrections before renaming them back to their original names.

executable file doesn't print anything

I've written a simple script, that basically looks like this:
#!/bin/bash
echo Hello World
I'm trying to run this in my unix terminal but it basically does nothing. no errors, no printing, nothing
[solgag#t2 ~]$ olga
[solgag#t2 ~]$
any ideas?
Try ./test instead. If you run just test, bash will look for an executable named test in $PATH and it will find it (or maybe execute its own built-in?) as test is a standard command in UNIX.
if you shell script name is olga you need to run in terminal as
$./olga
To run the script as specified above you need to have executable permissions you can add executable permission using chmod command
$chmod u+x ./olga
You can also run a bash script using sh command
$sh olga

Cygwin Shell Scripts

I'm not running cygwin, but I have the cygwin ash.exe in my %PATH% as sh.exe and have cygwin1.dll in %PATH%
I am trying to invoke some shell scripts (named with no extension) using sh -c shell-script-name but I get a "permission denied" error. If I run sh and run ./script I also get this error. I have a proper #!/bin/sh shebang line and even renaming to .sh or .exe has no effect. What should I do?
One thing to try to see if Windows permissions are causing a problem is to run Process Monitor and filter it for sh.exe and shell-script-name. That will probably show you if there's particular permission you don't have (eg you might have read but not execute permission).
Try also running the shell interactively, ie:
c:\>sh
sh# . ./script or
sh# sh -c ./script
If this works then you know that the cygwin part is working correctly. Another thing to check is that the line endings for your script are unix, as that can stop scripts from executing correctly.
Everything worked for me after doing:
$ chmod +x script

Resources