ctubbsii commented on issue #275:
URL: https://github.com/apache/fluo-uno/issues/275#issuecomment-977097428


   > > shift merely strips $1 out of the functions $@ argument list, so that $@ 
now contains only the stuff after the first argument. This is done correctly in 
both those methods, where $component is read from $1, and then shift is called 
to pass the remaining $@ to the next script.
   > 
   > But how does the second script know if $1 was stripped out or not?
   
   `$@` is just a variable name, local to the function, or if outside a 
function, local to the containing script. It represents the args passed to the 
function (or script), just as in `public static void main(String[] args)`, 
`args` represents the array passed to it.
   `shift` just modifies the array by moving the pointer to the first element 
to the next element, effectively creating a new array starting at the next 
element and continuing until the end of the original array. When it is placed 
as an argument for another script, the script initializes its own `$@` variable 
from the parameters passed to it.
   
   For example:
   
   ```bash
   # let $@ be the array ("item1" "item2" "item3")
   ./otherscript.sh "item0" "$@" "item4"
   # other script would create its own $@ that looks like ("item0" "item1" 
"item2" "item3" "item4")
   shift 2 # drop the first two items from this script's $@
   ./otherscript.sh "item0" "$@" "item4"
   # other script would now create its own $@ that looks like ("item0" "item3" 
"item4")
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to