What is the best to pass an array with specially characters as command l
From:
Peng Yu
Subject:
What is the best to pass an array with specially characters as command line arguments?
Date:
Sun, 6 Nov 2011 21:02:03 -0600
Hi,
Suppose that I have a verbatim string " a b c ( a'b | " in bash, and
I want to pass them as 6 command line arguments. I have to the
following conversion using quoteverb.sed to pass the 6 arguments
correctly to echo, which is a little bit cumbersome. I'm wondering if
there is any better way to pass the 6 arguments.
~$ cat quoteverb.sed
1s/^\s+//g
s/^\s\+//g
s/\s\+$//g
s/\s\+/\n/g
s/'/'\\''/g
s/^/'/gm
s/$/'/gm
s/\n/ /g
~$ cat main.sh
#!/usr/bin/env bash
verbatim_string=" a b c ( a'b | "
args="`echo \"$verbatim_string\" | sed -f quoteverb.sed`"
cmd="echo $args"
eval "$cmd"
~$ ./main.sh
a b c ( a'b |
--
Regards,
Peng