I want to know what principles I should use in order to write a bash script that takes its parameters in any given order. For example:
- Let's name my script: script.sh
- And let's say that I want it to take either no or at least two parameters.
- Now suppose that one standard parameter is the -f which specifies that the very next parameter is the name of the file I should process.
- Once more suppose that the given file is named: input.dat
- And finally (for the sake of the example), suppose that the last two parameters I can add are named: -print and -delete
What I am asking here is:
Is there a specific way (or even programming technique) I can use so that the parameters can be passed in any given order (besides the fact that the filename should always follow the -f parameter?
Here are some invoking examples:
- ./script.sh -f input.dat -print
- ./script.sh -print -f input.dat
The above two executions should produce the very same example!
When answering please do keep in mind that the real problem has many more parameters and different outcomes!