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

Re: bash variables



* 2011-02-27 09:12 (+0200), Teemu Likonen wrote:

> * 2011-02-25 14:21 (-0800), Mike McClain wrote:
>> root@/deb40a:~> FIND1="-maxdepth 1 -type f -print -name '*'"; \
>>     GREP="-v '\.\(deb\|gz\|tgz\|bz2\|tbz\|zip\)$'"; \
>>     find /home/mike/ $FIND1 | grep $GREP ; 

> Try removing the single quotes from hour FIND and GREP variables, or
> add another round of evaluation with "eval" command.

    (I don't know where the "hour" came from. It should be "your")

This should work:

    $ FIND1="-maxdepth 1 -type f -name '*' -print"
    $ GREP1="-v '\.\(deb\|gz\|tgz\|bz2\|tbz\|zip\)$'"
    $ eval find /home/mike $FIND1 | eval grep $GREP1

But really, if you are using Bash I'd suggest using arrays because
multiple evaluation, word splitting and escape rules become easily a
mess.

    $ FIND2=( -maxdepth 1 -type f -name '*' -print )
    $ GREP2=( -v '\.\(deb\|gz\|tgz\|bz2\|tbz\|zip\)$' )
    $ find /home/mike "${FIND2[@]}" | grep "${GREP2[@]}"


Reply to: