/etc/openhab/scripts is not really intended for shell scripts. It’s original purpose is to store Rules DSL scripts. You can put shell scripts there but you’ll have to always use the full path.
Every user has a home folder and the openhab user is no different.
When OH executes a command or shell, it started in it’s home directory.
For an apt/yum installed OH the home directory is /var/lib/openhab.
Since you are using what ever directory the spell accept is starting in, I’m going to guess your script is working the file, you are just looking in the wrong place. It’s almost certainly /var/lib/openhab/fileout.txt
The shell script is located in /etc/openhab/scripts. But when the script is run it’s run from $home, i.e ~openhab, i.e. /var/lib/openhab. When the script starts it gets pwd which is the folder the process is in, not the folder where the shell script file itself is.
No, and yes, I know. What I wanted to say is that the different output is weird.
As expected the output of pwd on my device was /var/lib/openhab.
That’s why I requested the OP to add an echo $PWD to his script as I was confident that the file was created somewhere else.
However, the output of the OP’s script was /etc/openhab/scripts
Probably there is a cd /etc/openhab/scripts command somewhere before.
in that case the current path of the user was /etc/openhab/scripts when he executed sudo -u.
sudo -u does not change the path that is why it is /etc/openhab/scripts.