I am writing a bash script to execute an application. But, the application needs files stored in a particular directory. If I use systemd then I can use WorkingDirectory setting to define on which directory the service will be launched. But I am not sure how this can be done within bash script. Can anyone please let me know how to achieve this?
#!/bin/bash
SERVICE="test"
if pgrep -x "$SERVICE" >/dev/null
then
echo "$SERVICE is running"
else
echo "starting $SERVICE"
# The application "test" uses files stored in dir /home/example/
/usr/bin/test
exit 0
fi
Is doing cd /home/example/ before executing the application enough?
cd /home/exampleat start of script should be enough. just taste it ! (sorry can't resist the pun)