csv as argument
Vu Pham
vu
Thu Jul 19 09:40:42 PDT 2007
On Thu, 2007-07-19 at 17:24 +0100, Jorge Almeida wrote:
> This is probably a stupid question, but anyway. Is there some way to
> coax bash into accepting a csv string as argument? Like this:
> myprogram "aaa"," gg","aa,b","a""n"
>
> All this stuff should constitute a single argument. The idea is that the
> program itself would do the parsing.
> The shell removes the quotes. Enclosing the whole string in single
> quotes would do the work, but then what if the string itself has single
> quotes?
>
> Any idea? Or is this the wrong problem by all accounts?
>
If your arg is "123', \"456, 1121" then the shell will understand it as
one single arg of 123', "456, 1121
i.e., if you quote the arg by double quote, then single quote be not be
stripped off. And if you want to have double quote inside the arg, then
escape it with \. If you want to have \ in the arg, then use \\.
For example:
vu at ef:/home/vu> more a.sh
echo $1
vu at ef:/home/vu> ./a.sh "123', \"456, 1121 \\"
123', "456, 1121 \
More information about the Linux-users
mailing list