In this lecture we will play with challenging get optical month.
Great script called Get off the stage and start with Shaban
from the beginning.
We can print all arguments given to our script do not assign it represents all arguments.
Now we into of the variable output of get optical month where we will have some short positional parameters.
So we need to use and dash 0 followed by let's say parameter a which will have optional argument and
if it is optional we need to provide two columns parameter B must have some argument that's why we want
to call on and parameters see the e won't have any arguments that's why we don't specify any call on
after them now right.
Dash dash long for the long parameters and there we will have parameter file with optional argument
parameter name with the required argument and parameter a help without any argument at the end of forget
command we need to specify arguments which are going to be passed so degradation space dollar sign and
by ls set command we are changing initial arguments and for being sure the change really happened we
can print all arguments after they were passed would get up to command
so just to recap how get opt works and get up command returns past arguments in order to pass them we
need to specify to get opt command what parameters we are taking into account if we are specifying short
parameters that means parameters starting with dash for example dash a we need to specify them after
this all parameter.
So here we have parameter a followed by two columns which means that parameter 8 can be followed by
optional argument then we have parameter B with column that means with required argument then we have
parameters c d and e which don't take any arguments Evie in our script want to have long parameters
as for example designated file we need to specify them after David's long parameter of course we need
to tell to get up to command what arguments we want to pass and we can do that by using digital age
space the latter sign at
So now we'll do the same we did with our script file check it as if we need to process pass arguments
one by one so while number of arguments is greater than zero 0 exit could do better inside while loop
if first argument is a we can print barometer a selected
so if we choose def a if if A is first argument print parameter a
selected with argument dollar assigned to.
Now we need to get rid of parameter and argument by to shift commands
or we can just override shift tool it does the same thing as to shift commands
for option B and we will bring something similar.
So just copy.
Option A and edit it
for Option C we will print Option C selected
or parameters c selected and we will get rid of this parameter by shift command.
No need for another shift command.
As if it didn't specify column after this parameter.
So no argument is expected here.
Option D and E will be pretty much the same so just copy Option C and edit it.
In case long option parameter a file was used we will print parameter file selected wait
argument
dollar assigned to our assigned to represent that argument that date value of the argument.
And of course she could do to get rid of arguments.
An optional argument.
Sorry I said you only to get rid of parameters and optional argument in case no argument was selected
as it is optional though are assigned to will be an empty string the same.
Of course we can do for name parameter
shift too and we have.
But I mean the help so for parameter help we can print parameter to help selected
and there is no argument so just only one shift.
And for cases something else was selected
we can just posit that option of a puzzle does pass that argument and it's all we can now say with the
script.
Ground execute permissions
and we can run it.
Firstly drive it Dash CDE
and we see that it transform this city into dash C dash D and dash e gate.
Now we can do some little change we can add parameter a followed by optional argument without any space.
And an optional argument is called optional in my case.
And we see that.
Get up.
Pass it to dash a and optional argument which is great.
It works.
If you don't specify arguments for parameter a.
We see that parameter a was selected with non existing argument.
Now let's say at option B
followed by argument call required.
Because in Get up come on to B wrote one column after parameter B and the long option file followed
by equal sign optional and add also long option name parameter with argument required.
And we see that it was part as well
in case that we didn't specify required argument it can be for example for a parameter name we got at
or from get opt command option name requires an argument.
Now if we didn't specify optional argument for a parameter file we see that parameter file was selected
with no argument.
Great but what happens if the after parameter a file put a value something of value something wasn't
kept as file parameter needs equal sign of an optional argument is given.
If we go back to the script we can change it a little bit we will edit section for case something else
was given as an argument and we will write what was given what argument was given.
Now around the script again and we see that we are printing two dashes which marks the end of arguments
passed by get up and then we see something which is argument which wasn't which wasn't passed by.
Up and Get Up but part can be really challenging.
It has own rules which needs to be followed but if you play with it more you will get used to it.
Now it's up to you and the situation what method to choose.
You can take care of scripts arguments yourself as we did for file check script or you can use quite
easy get opt which has the limitation of not processing along parameters or you can use more advanced
get opt.