Friday 15 February 2013

linux - bash command line arguments into an array and subset the array based on the parameter value -


I am trying to get the input parameters for my bid script. Testbash.sh 4 1 2 4 5 Science A P * I want to get these arguments as an array which I used to get $ @ to get everyone in an array. Now on the basis of the first argument, I have to subscribe the rest. The first number here is 4, so the second argument should be saved as an array of fifth arguments [1 2 4 5] and the remaining arguments in a second array.

I tried it

array = ($ @) len = $ {# array [@]} args = $ {array [@]: 0: $ len - $ {array {1}}} Encoded $ args

I tried to get the first part but I got an error syntax error in the expression (error token ": -4") when I went this way "testbash.sh 4 1 2 4 5 Science AP" "

It is: P> Instead of using an intermediate array, work directly from logic Does this intermediate array It will be easy to use, at least in the same way, but remember that the array starts from indexing 0, whereas parameter indexing effectively starts at 1 (because parameter 0 is the name of the command). Note that quotes are important: Without them, command line logic globe extension and word segmentation will be passed through an additional time; In fact, you can use the command line arguments to quote Lose it.

No comments:

Post a Comment