Manually start Home Assistant in shell script

I performed a manual installation of HA on my RPi, but this is a test RPi and I have other software that I run on it from time to time, so I only want HA running when I want to play with it. HA starts fine using the commands from the installation instructions:

sudo -u homeassistant -H -s
source /srv/homeassistant/bin/activate
hass

However, I cannot figure out how to get these into a shell script and run them in order to execute Home Assistant. Simply placing them in a shell script as above gives me a “: No such file or directory” error. Does anyone have a shell script to manually start HA?

did you make your shell script excutable?

chmod +x scriptname

Did you provide the path to the script? If you are in, say, your home directory, then just running

scriptname

will not work as the script is not in $PATH. You need to give a path, like

./scriptname

or

/home/nick/scriptname

Thanks for the response. I had permissions and running the script covered (I’ve come at least that far over the years). The first issue was the old end-of-line character problem that was tripping me up (still use VS Code on a PC for editing). Then, to get the commands above to work in a shell script, I had to do this, which I found in other HA scripts for updating and such:

#!/bin/bash

echo "Starting Home Assistant"

sudo -u homeassistant -H -s<<"EOF"
source /srv/homeassistant/bin/activate
hass
EOF

Something about starting a new shell w/ sudo and/or activating the virtual environment were just not bash friendly, I guess.

Yeah I wasn’t sure about your scripting knowledge and started at the beginning!