[bash] How to access command line arguments of the caller inside a function?

My solution:

Create a function script that is called earlier than all other functions without passing any arguments to it, like this:

! /bin/bash

function init(){ ORIGOPT= "- $@ -" }

Afer that, you can call init and use the ORIGOPT var as needed,as a plus, I always assign a new var and copy the contents of ORIGOPT in my new functions, that way you can keep yourself assured nobody is going to touch it or change it.

I added spaces and dashes to make it easier to parse it with 'sed -E' also bash will not pass it as reference and make ORIGOPT grow as functions are called with more arguments.