[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: how to pass arguments with space inside?
From: |
lehe |
Subject: |
Re: how to pass arguments with space inside? |
Date: |
Thu, 9 Apr 2009 16:33:37 -0700 (PDT) |
Forgot to say in the bash script, the call to the executable is like:
my_executable ${ARG_OPTS}
lehe wrote:
>
> Actually in the bash script there is a command that passes "--options='-t
> 0 -v 0'" as argument to an executable. I just found if I double quote
> --options='-t 0 -v 0' as argument to the bash script, then the '-t 0 -v 0'
> as a whole can be preserved until reaching the command invoking the
> executable. However the '-t 0 -v 0' is not passed as a whole to the
> executable, but splitted by spaces again.
> This may sounds like the problem of calling the executable, however when
> directly invoking the executable from terminal, either --options='-t 0 -v
> 0' or --options="-t 0 -v 0" without quoting could be passed successfully
> as argument.
>
> Hope that I could explain my question clearly enough. Really appreciate
> your advice!
>
>
> lehe wrote:
>>
>> Thanks Mike.
>> Could you explain it a little? I don't quite get it. How to apply this to
>> argument parsing?
>>
>>
>> Mike Frysinger wrote:
>>>
>>> On Thursday 09 April 2009 16:46:27 lehe wrote:
>>>> I was wondering how to pass arguments with space inside. For example,
>>>> my
>>>> bash script looks like:
>>>>
>>>> #!/bin/bash
>>>> ARG_OPTS=""
>>>> while [[ -n "$1" ]];
>>>> ARG_OPTS="${ARG_OPTS} $1"
>>>> shift
>>>> done
>>>>
>>>> If I pass an argument like "--options='-t 0 -v 0'", then it would be
>>>> splitted by the spaces inside, ie "--options='-t", "0", "-v" and "0".
>>>>
>>>> How can I achieve what I wish?
>>>
>>> use arrays
>>>
>>> $ f=( a "b c" d)
>>> $ printf '%s\n' "${f[@]}"
>>> a
>>> b c
>>> d
>>> -mike
>>>
>>>
>>>
>>
>>
>
>
--
View this message in context:
http://www.nabble.com/how-to-pass-arguments-with-space-inside--tp22978918p22980936.html
Sent from the Gnu - Bash mailing list archive at Nabble.com.
- how to pass arguments with space inside?, lehe, 2009/04/09
- Re: how to pass arguments with space inside?, Mike Frysinger, 2009/04/09
- Re: how to pass arguments with space inside?, lehe, 2009/04/09
- Re: how to pass arguments with space inside?, Mike Frysinger, 2009/04/09
- Re: how to pass arguments with space inside?, lehe, 2009/04/09
- Re: how to pass arguments with space inside?, Chris F.A. Johnson, 2009/04/09
- Re: how to pass arguments with space inside?, lehe, 2009/04/10
- Re: how to pass arguments with space inside?, Greg Wooledge, 2009/04/10
- Re: how to pass arguments with space inside?, Eric Blake, 2009/04/10
- Re: how to pass arguments with space inside?, Chris F.A. Johnson, 2009/04/11