0

So here's is the scenario, I have a shell script that based on a network command it execute an action, it may be a service restart or stop. That part is working fine, but I'm stucked at a part that I need to guarantee that it can be more flexible, i.e, that I can add some services later without touching the main script. So what I have in mind is to separate the script into multiple scripts, like interfaces.d/ does, but instead of a config file I want to store some code inside of it and load it when the script is called. Problem is, for each "process" I want to create a separate file with an if within it. Is that even possible?

Thnaks.

1 Answer 1

1

Answering my own question, actually you can do that.

What I did was iterate through the files in the .d folder and executed them with:

. $filename

Note that there's a space between the dot and the file.

Hope this helps someone

1
  • Alternatively, you could define several functions in a single file, source that file with a single dot command . $filename and for each task execute the relevant function. This will reduce the number of files to be sourced. Commented Dec 23, 2017 at 20:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .