i have a requirement where i have to run a script with at least 25 arguements and position of arguements can also change. the unapropriate way is like below. can we achieve this in more good and precise way??
You also need to be away that referring to positional parameter $25 will usually end up being interpreted as ${2}5 , i.e. the value of parameter two, followed by the literal value 5.
Someone in their wisdom here managed to code scripts that look like this:-
date_req=$22013
The idea being that the month is passed in as positional parameter 2 and the year is appended. Apart from looking awful, of course we then ended up editing the script each year - oh, and the year was not necessarily the calender year that the process was running in either.
It works for us (very badly and will be replaced soon) but you might get very confused by the use of:-
The standards state that positional parameters with more than a single decimal digit must be specified with braces. I.e., ${25} will expand to the value of the 25th positional parameter and $25 will expand to the value of the 2nd positional parameter followed by the string 5 .
Rather than writing code that uses $25 to append "5" to the expansion of $2 , I write it as ${2}5 to make it less likely to confuse people who read my code; but experienced shell programmers should know how this works.