help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Quoting in variables to be used as command args


From: suvayu ali
Subject: Re: [Help-bash] Quoting in variables to be used as command args
Date: Tue, 5 Jun 2012 20:36:22 +0200

Hi Geir,

On Tue, Jun 5, 2012 at 7:54 PM, Geir Hauge <address@hidden> wrote:
> 2012/6/5 suvayu ali <address@hidden>:
>
> Never mash multiple arguments into a single string. Use arrays or
> functions. For this case, an array:
>
> [[ $blah ]] && findopts+=( -name "*.$blah" )
> #...
> find . "address@hidden"
>
> See http://mywiki.wooledge.org/BashFAQ/050
>

I looked at that page and tried to use arrays earlier. But I must have
done something subtly wrong. Adapting your examples work wonderfully.
:)

>
> Don't fill an array using array=( $(command substitution) ), you get the
> same problem with wordsplitting and pathname expansion as with your
> findopts string. Use a while read loop instead.
>
> files=()
> while IFS= read -r -d '' file; do
>    files+=("$file")
> done < <(find "$srcdir" -type f \( "address@hidden" \) -print0)
>

A few questions, I don't understand the use of two '<' characters. Why
is one input redirection not enough? Why are the escaped parentheses
around findopts required? Just using "address@hidden" seems to work in
my script.

> Note that -print0 is a non-POSIX extension to find, but GNU and BSD find
> has it.
>

I am aware of this subtlety, thanks for reminding me.

Thanks a lot for your comments. I learnt quite a bit. :)

-- 
Suvayu

Open source is the future. It sets us free.



reply via email to

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