Shell_command error 127

Logger: homeassistant.components.shell_command
Source: /Users/server/homeassistant/lib/python3.9/site-packages/homeassistant/components/shell_command/__init__.py:115

* Error running command: `/Users/server/.homeassistant/scripts/restart_ha`, return code: 127

NoneType: None

I can run the command in the venv and it works.
I can open the shell script directly and it works.

#!/bin/bash
launchctl stop org.homeassistant 
launchctl start org.homeassistant

When I run this script with shell_command, it just doesn’t work.

I can play audio in the shell with “afplay test.mp3”, so shell command basically works.

#!/bin/sh

FILE=/Users/server/Movies/YouTube/lock.txt
if [ ! -f “$FILE” ]; then
touch /Users/server/Movies/YouTube/lock.txt

for file in $(cat /Users/server/Movies/YouTube/request.txt); do yt-dlp -i -w -f “(bestvideo+bestaudio/best)” --download-archive “/Users/server/Movies/YouTube/archive.txt” -o “/Users/server/Movies/YouTube/%(title)s.%(ext)s” “$file”; done

for file in $(cat /Users/server/.homeassistant/scripts/ytdl/abos.txt); do yt-dlp -i -w -f “(bestvideo+bestaudio/best)” --dateafter now-2days --match-filter “!is_live” --playlist-end 2 --download-archive “/Users/server/Movies/YouTube/archive.txt” -o “/Users/server/Movies/YouTube/%(title)s.%(ext)s” “$file”; done

This code is inside a shell:
works
touch /Users/server/lock.txt
fails with error code 1
rm /Users/server/lock.txt

If I use open /Users/server/script instead of /Users/server/script it works when opening the Terminal.

I think the problem is that the user homeassistant (from venv) does not have change rights. It can only execute, read and write). How can I change that?

I can run the script from venv, so the issue must be within HA…

I know, it’s a bit late, but did you find a solution? I nowhere found a description what errors 127 and 255 mean in this context. Poor documentation.