0

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?

2
  • 1
    Have you actually tried to do this? That would give you the information on whether it does or doesn't work. If it doesn't work, then you can edit the question and add error messages, what happened, what is supposed to happen, etc. Commented Dec 20, 2022 at 13:02
  • short answer is yes cd /home/example at start of script should be enough. just taste it ! (sorry can't resist the pun) Commented Dec 20, 2022 at 13:12

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.