A collection of shell libraries/functions.
Filename: dynamic_parsers.sh
Include in script: source <path-to-repo>/dynamic_parsers.sh
Parses all arguments passed to a script or function. The varables do not need to be defined beforehand.
- If a
-ftrue false switch is passed, a varible namedfis created and set toyes. - If a
-f <arg-value>is passed, a variable namedfis created and set to<arg-value>. - The functionality above is equivalent for parameters passed with a
--prefix. e.g.--force
$@:Inherent form caller script/function.
Dynamic variables based on the name of passed parameters.
Parses all parameters passed to a script or function for the specified TYPE and NAME given.
If a match is found, a dynamic variable will be created with the name of the passed parameter. The value of this parameter will depend on the TYPE specified.
-
TYPE:
-
switch:true or false parameter which does not accept an argumet. Will only be detected if passed with a short ('-') or long ('--') prefix. e.g.
-verboseor--verbose. -
short:Parameter which accepts an argument. Will only be detected if passed with a short (
-) prefix. e.g.-p 8572or-port 4545. -
long:Parameter which accepts an argument. Will only be detected if passed with a long (
--) prefix. e.g.--p 8572or--port 4545. -
shortlong:Parameter which accepts an argument. Will only be detected if passed with a short ('-') or long ('--') prefix. e.g.
-port 4545or--port 4545.
-
-
NAME: The varable name in which to save the value of the argument passed to the parameter. This will also be the name of the parameter.
$@:Required in order to pass the callers parameters into the function.
-
param switch debug $@Parses parameters and matches the parameter
-debugor--debug. After a match, $debug = 'yes'. -
param short l $@Parses parameters and matches the parameter
-l 386. After a match, $l = 386. -
param long length $@Parses parameters and matches the parameter
--length 386. After a match, $length = 386
A Dynamic variable based on the positional TYPE and NAME parameters.
Run ./test_parsers.sh
Edit test_parsers.sh and change the if statments to test each function.
OR
Run ./test_parsers.shunit2 (Requires shunit2 to be installed)
Filename: std.sh
Include in script: source <path-to-repo>/std.sh
See script file (for now).
Run ./test_std.sh
GithubAction: here