You say it works when running from the command line. What is the output of which bash ? Perhaps the first line of the script is incorrect for your OS. Sometimes it is in /usr/bin
Your problem then is that your script is bad. bash lives in /bin not /usr/bin.
[21:08:12] openhabian@openhab:~$ ls /usr/bin/bash
ls: cannot access '/usr/bin/bash': No such file or directory
[21:08:12] openhabian@openhab:~$ ls /bin/bash
/bin/bash
Where is your script located in ?
The error message means that myscript.sh cannot be found by using the content of the PATH variable.
If you do a
echo $PATH
you will see the directories that are being used to search for myscript.sh.
Running
bash myscript.sh
I assume that you are executing the script from within the directory where the script is located.
So you either need to move the script to a directory that is listed in the PATH environment variable or you need to add the directory to the PATH environment variable.
Path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
what I do not understand is, why there haven’t been any problems with openHABian 1.6.0 image…
Please help me to understand:
If I change the directory to where the .sh script is located, e.g. /etc/openhab/scripts and run it from there, the path to script location does not need to be in PATH-Environent, right? At least this is how it works under DOS or Windows cmd (I know, this does not necessarily mean it is the unser Linux…)
From my little experience: I think under 1.6.0 I was able to execute any .sh script from any location
To be able to run a script from the current directory you are in you need to add the . ( dot ) direcotry to the PATH.
then the . needs to be in the PATH.
You also can run the script by prepending the dot like: ./myscript.sh ( as long as you are in the directory ) or /etc/openhab/scripts/myscript.sh to execute the script.
Dot is not included in the search PATH e.g. for root to not get vulnerable scripts being executed by accident. E.g. In case a user that would like root to get executed something puts a replacement for the ls command in his directory then asks root to change into his directory and do a ls command instead of the system ls command the users ls command would be executed in case root would have . as first item in his PATH environment variable.
I do not know all the history of openahbian but in case you mean you could store scripts like /dirA/A, /dirB/B, /dirC/C and then goto e.g. /etc and run A, B, C I definitely can say that this did not work as the system needs to look into the PATH variable to find this scripts, executables.
So just make sure that you always use the absolute path and script name and it will be executed and does not need to be found by the PATH environment variable.