[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
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
- What is the best to pass an array with specially characters as command line arguments?,
Peng Yu <=
- Message not available
- Message not available
- Re: What is the best to pass an array with specially characters as command line arguments?, Clark J. Wang, 2011/11/06
- Re: What is the best to pass an array with specially characters as command line arguments?, Peng Yu, 2011/11/06
- Re: What is the best to pass an array with specially characters as command line arguments?, Clark J. Wang, 2011/11/07
- Re: What is the best to pass an array with specially characters as command line arguments?, Peng Yu, 2011/11/07
- Re: What is the best to pass an array with specially characters as command line arguments?, Dennis Williamson, 2011/11/07
- Re: What is the best to pass an array with specially characters as command line arguments?, Peng Yu, 2011/11/07
Re: What is the best to pass an array with specially characters as command line arguments?, Stephane CHAZELAS, 2011/11/07