I call my script:
$ ./script 'a!#*`*&
^$' "sdf sdf\"qw sdsdf" 1 -- 2 3
It gets arguments:
1: a!#*`*&
^$
2: sdf sdf"qw sdsdf
3: 1
4: --
5: 2
6: 3
If I need to call something with the same arguments locally, I do this:
someprogram "$@"
But how can I put all that array to a string (to store in file or in environment variable or pass over TCP eaisly) and then turn it back to command line arguments somewhere? I want it to be simple, short and secure.
export CMDLINE="$@"
# What is in CMDLINE now? Escaped or not?
sh -c "someprogram $CMDLINE"
# Will it do what I mean?
Ideally I want two programs: the first turns turns command line paramerets into a [a-zA-Z0-9_]*
string, the other turns it back to command-line parameters I can use.
Update: written 2 versions of pairs of scripts. Which is more useful?