本文发表在 rolia.net 枫下论坛cd:/tmp/test # ls -l
total 40
drwxr-xr-x 4 root root 4096 Apr 21 04:55 .
drwxrwxrwt 103 root root 12288 Apr 21 04:51 ..
-rw-r--r-- 1 root root 11 Apr 21 04:55 a
-rw-r--r-- 1 root root 15 Apr 21 04:55 b
drwxr-xr-x 2 root root 4096 Apr 21 04:54 bb
-rw-r--r-- 1 root root 13 Apr 21 04:52 c
-rwxr-xr-x 1 root root 124 Apr 21 04:53 thesh
drwxr-xr-x 2 root root 4096 Apr 21 04:53 x
cd:/tmp/test # cat a
aab
bb
cc
:wqcd:/tmp/test # cat b
aab
bb
cc
:wq
cd:/tmp/test # cat thesh
#!/bin/sh -x
mkdir $1
for File in *
do
result=`grep -l $1 $File`
if test "$File" = "$result"
then
cp $File $1/$File
fi
done
cd:/tmp/test # ./thesh bb
+ mkdir bb
++ grep -l bb a
+ result=a
+ test a = a
+ cp a bb/a
++ grep -l bb b
+ result=b
+ test b = b
+ cp b bb/b
++ grep -l bb bb
+ result=
+ test bb = ''
++ grep -l bb c
+ result=
+ test c = ''
++ grep -l bb thesh
+ result=
+ test thesh = ''
++ grep -l bb x
+ result=
+ test x = ''
cd:/tmp/test # ls bb
. .. a b
cd:/tmp/test #更多精彩文章及讨论,请光临枫下论坛 rolia.net
total 40
drwxr-xr-x 4 root root 4096 Apr 21 04:55 .
drwxrwxrwt 103 root root 12288 Apr 21 04:51 ..
-rw-r--r-- 1 root root 11 Apr 21 04:55 a
-rw-r--r-- 1 root root 15 Apr 21 04:55 b
drwxr-xr-x 2 root root 4096 Apr 21 04:54 bb
-rw-r--r-- 1 root root 13 Apr 21 04:52 c
-rwxr-xr-x 1 root root 124 Apr 21 04:53 thesh
drwxr-xr-x 2 root root 4096 Apr 21 04:53 x
cd:/tmp/test # cat a
aab
bb
cc
:wqcd:/tmp/test # cat b
aab
bb
cc
:wq
cd:/tmp/test # cat thesh
#!/bin/sh -x
mkdir $1
for File in *
do
result=`grep -l $1 $File`
if test "$File" = "$result"
then
cp $File $1/$File
fi
done
cd:/tmp/test # ./thesh bb
+ mkdir bb
++ grep -l bb a
+ result=a
+ test a = a
+ cp a bb/a
++ grep -l bb b
+ result=b
+ test b = b
+ cp b bb/b
++ grep -l bb bb
+ result=
+ test bb = ''
++ grep -l bb c
+ result=
+ test c = ''
++ grep -l bb thesh
+ result=
+ test thesh = ''
++ grep -l bb x
+ result=
+ test x = ''
cd:/tmp/test # ls bb
. .. a b
cd:/tmp/test #更多精彩文章及讨论,请光临枫下论坛 rolia.net