Hi All,
I would like to improve my bash scripting skill and found a problem which I do not understand. Task is to search and print files in directory (and subdirecories) which contains its own name. Files can have spaces in name.
This one works fine for files in main directory, but not for files placed in subdirectories:
find . -type f -exec sh -c "echo {} | sed s/'\.\/'/''/g" \; | xargs -I'{}' grep -H {} {} | cut -f1 -d:
So I tried to add basename in subshell and it is not working as I expected. There is no result. Path is printed like before.
[ok@x60 test]$ find . -type f -exec sh -c "echo {} | sed s/'\.\/'/''/g" \; | xargs -I'{}' echo grep -H `basename {}` "{}"
grep -H olooo olooo
grep -H 1 ib_iser 1 ib_iser
grep -H ala ma/00.00 kintegrityd ala ma/00.00 kintegrityd
When I changed basename to dirname to check what happens, I got:
[ok@x60 test]$ find . -type f -exec sh -c "echo {} | sed s/'\.\/'/''/g" \; | xargs -I'{}' echo grep -H `dirname {}` "{}"
grep -H . olooo
grep -H . 1 ib_iser
grep -H . ala ma/00.00 kintegrityd
So, why basename and dirname act like this? Thank you for any help on this