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

Re: bash variables



On 25.02.2011 23:21, Mike McClain 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.
Thanks,
Mike McClain

I'd do:

find . -maxdepth 1 -type f -regextype posix-egrep -regex '.*\.(deb|gz)'

...

F="find . -maxdepth 1 -type f -regextype posix-egrep -regex .*\.(deb|gz)"
$F



Reply to: