0

For context: I've written a bash script for maintaining my always-online minecraft server. Recently, I've decided that I also want to host another world in sessions. Rather than editing my script everytime I want to switch worlds, I want to pattern match a worldname starting with a hyphen, passed as argument.

For example:

/srv/minecraft/minecraft.bash -myworld start console

Note: my script tries to execute each passed argument as if it were a function. If no option is passed, nothing should happen, so I plan to look for a null WORLD_NAME variable, then set it to DEFAULT_WORLD_NAME. My goal is to keep the script itself as simple as possible.

Basically, I want to parse any option and use it's name as value.

Is there any way to do this natively supported in bash? Additionally, if not, what would be the simplest way to separate and parse arguments with a starting hyphen manually?

HYBR1D
  • 446
  • 2
  • 6
  • 19

0 Answers0