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

Re: bash variables



Hi Mike,

Please add OT to subject ;-)

On Fri, Feb 25, 2011 at 11:21 PM, Mike McClain <mike.junk@cox.net> wrote:
> I occasionally have problems with bash variables, for instance
> the following command lists (along with everything else)
>  2 *.deb files in /home/mike/
>
> root@/deb40a:~> FIND1="-maxdepth 1 -type f -print -name '*'"; \
>    GREP="-v '\.\(deb\|gz\|tgz\|bz2\|tbz\|zip\)$'"; \
>    find /home/mike/ $FIND1 | grep $GREP ;
>
> while without variables;
> root@/deb40a:~> find /home/mike/ -maxdepth 1 -type f -print -name '*' |
>    grep -v '\.\(deb\|gz\|tgz\|bz2\|tbz\|zip\)$'
> does not list the 2 *.deb files.
>
> In the same vein this command lists nothing:
> root@/deb40a:~> FIND="-name '*'"; find /root/bin $FIND
> while
> root@/deb40a:~> find /root/bin -name '*'
> lists 25 files.
>
> This only bites me once in a while but when it does it can be very
> frustrating so any hints / tips are welcome.
If you want to view what is happenning here:

set -x;  # and then exec your sentences

You can use set -f to disable file pattern expansion:

FIND='-name *'; set -f; find . $FIND; set +f

I don't know how you can use quoted "*" inside that variable in find
instruction ... maybe  comp.unix.shell group could be a better place
to be answered your question in a nice way

Regards,


Reply to: