optargs processing

Hello i'm writing some analyzing script and i'm giving to my program these parameters, for example:

./procinfo -r tmpfile sh -c "cat tmpfile"

where -r is proccessed in getopts and it takes an argument by OPTARG..
The thing is I need to save this part to some variable:

sh -c "cat tmpfile"

I've tried it as ( after shifting, of course - shift $(($OPTIND - 1)) )

VARIABLE="$"
or other ways..
$

$@
"$@"

It only saves the part but WITHOUT the quotation marks and that's why i'm writing here..
Do you know, where the problem could be?
I'm pretty confused by that :confused:
thanks for answers!

IMHO this is incomprehensible.

What Operating System are you using? This may lead is towards the syntax for "procinfo". Of course "procinfo" could be a local script in which case please post the script. If it's a script, please post what script language you use.

Please re-phrase the initial post showing what input you have, what processing you desire, and what output you expect.

If your test doesn't work, please show what you typed, what you expected to happen, and what actually happened - also showing any error messages.

I don't understand it as well.
Totally new file:

$ cat new
echo "$@"
echo $@
echo "$"
echo $

./new -r. sh -c "cat tmpfile"

-r. sh -c cat tmpfile
-r. sh -c cat tmpfile
-r. sh -c cat tmpfile
-r. sh -c cat tmpfile

Of course I need this output:

-r. sh -c "cat tmpfile"

Tried Linux and Solaris server. Shit happens. I don't get it at all.
If anything "procinfo" script is here

I think I almost understand.

Try these single quotes to protect the double quotes from the shell.

./new '-r. sh -c "cat tmpfile"'

-r. sh -c "cat tmpfile"
-r. sh -c "cat tmpfile"
-r. sh -c "cat tmpfile"
-r. sh -c "cat tmpfile"

Note that I have cut/paste from your most recent post. The actual command string makes no sense whatsoever but the problem you describe appears to be about preserving double quote characters.

---------- Post updated at 04:48 ---------- Previous update was at 04:05 ----------

========================================================================================

Sorry, I cannot relate what you are typing to the syntax for the shell script called "procinfo" as described within the script which we find on on the Internet link you posted. There is no "-c" switch.

It is not at all clear what you want "procinfo" to do but I am concerned that you may be trying to analyse

sh -c "cat tmpfile"

which makes no real sense in shell and will definitely not work in the context of the script "procinfo" because it would start a subshell.

Maybe you mean this? Could be wrong because I am not going to analyse "procinfo". Totally untested but just to illustrate that I guess that you probably do not want to truss "sh" but that you probably do want to truss "cat"? Obviously the command executed in the end may not actually be "truss" because the script "procinfo" tries to work out what Operating System you have.

./procinfo -r tmpfile cat tmpfile

In conclusion this is not really a question about shell parameters it is about how to work some shell script called "procinfo" which you have found on the Internet.

Without optargs, "raw" method:

#!/bin/ksh or bash or dash or ...
#procinfo -r tmpfile -c "cat tmpfile"
ropt=""
copt=""
while [ $# -gt 0 ]
do
        opt="$1"
        case "$opt" in
             -r|--roption) ropt="$2" ; shift ;;
             -c|--coption) copt="$2" ; shift ;;
             --) shift; break ;; # no more options
             -*) echo "usage:$0 ....." >&2  ; exit 1 ;;
             *) break;; # not option, rest line is argument(s)
         esac
         shift
done

But if you like procinfo -r tmpfile sh -c "ls some" -c is not option, then syntax must be
procinfo -r tmpfile "ls -al"
or
procinfo -r tmpfile -- "ls -al"
or
procinfo -r tmpfile -- ls -al

for previous generic template.
-- is "standard" option which tell that no more option, the rest of line is arguments.

...
done
data="$@"
echo "$data"
# do it
$data