bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What is the best to pass an array with specially characters as comma


From: Clark J. Wang
Subject: Re: What is the best to pass an array with specially characters as command line arguments?
Date: Mon, 7 Nov 2011 13:00:15 +0800

On Mon, Nov 7, 2011 at 12:56 PM, Peng Yu <pengyu.ut@gmail.com> wrote:

> Hi Clark,
>
> >> > v="  a b c ( a'b | "
> >> > a=( $v )
> >> > echo "${a[@]}"
> >
> > There's a @ char here.
>
> I see. It's my mistake.
>
> But I want to pass the 6 short arguments instead of 1 long argument to
> echo.


What do you mean by "1 long argument"?

[bash-4.2.10] # cat foo.sh
v="  a b c ( a'b | "
set -o noglob
a=( $v )
set +o noglob
for i in "${a[@]}"; do
    echo "$i"
done
[bash-4.2.10] # bash foo.sh
a
b
c
(
a'b
|
[bash-4.2.10] #


> (echo is just an example, it can be any command that accepts
> multiple arguments.)
>
>
> ~$ cat ./main1.sh
> #!/usr/bin/env bash
>
> #set -o noglob
> verbatim_string="  a b c ( a'b | "
>
> args=( $verbatim_string )
> #set +o noglob
>
> echo "${args[@]}"
>
> ~$  ./main1.sh
> a b c ( a'b |
>
>
> --
> Regards,
> Peng
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]