bugfindutils - Bugs: bug #31240, find -exec can't access shell...

 
 

bug #31240: find -exec can't access shell environment (alias or functions)

Submitted by:  Leif W <warp9pnt9>
Submitted on:  Mon 04 Oct 2010 12:42:35 PM UTC  
 
Category: findSeverity: 3 - Normal
Item Group: Wrong resultStatus: Invalid
Privacy: PublicAssigned to: James Youngman <jay>
Originator Name: Open/Closed: Closed
Release: 4.4.2Fixed Release: None

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Tue 05 Oct 2010 10:13:51 PM UTC, comment #1:

find -exec is designed not to launch commands via the shell. This is standard feature of all implementations of find, and it's intended that way in order to better handle unusual filenames.

You can achieve the effect you want by using sh -c as the 'command' for find -exec and executing your pipeline that way. There are examples of this in the 'Common Tasks' section of the Texinfo documentation.

(I'm marking this bug "invalid" because it's not a bug in find.)

James Youngman <jay>
Project AdministratorIn charge of this item.
Mon 04 Oct 2010 12:42:35 PM UTC, original submission:

Using diff 4.4.2 in MSYS.

I wanted a quick way to capture file name, size, modification and md5sum all in one tab separated line. I decided to use find -exec, and learned the limitation of the -exec commands. So I wrote a small shell function (below), which does what I want.

function f_md5stat ( )
{
stat --printf="%n\t%s\t%y\t$md5" $1; md5sum "$1" | cut -d\ -f1;
}

However, find can not access anything in the shell's environment. Not sure if that is by design, but seems to be an odd limitation.

I put the function into a file and put the file into /bin, for a quick test, and it will work that way. However, I wish to have several functions in one file. The workaround I have found is to use a "case" to detect the way the script was called (or what the 0th or 1st arguments were), and use that to determine which internal shell function to use.

The other custom function will call find on 2+ directory trees, pass each argument to the f_md5stat function, to generate detailed lists, which I will then use for the purpose of comparing and (for now, manually) synching files.

Leif W <warp9pnt9>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

Attached Files
file #21608:  md5stat added by warp9pnt9 (257B - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by jay (Posted a comment)
  • -unavailable- added by warp9pnt9 (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 4 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Tue 05 Oct 2010 10:13:51 PM UTCjayStatusNone=>Invalid
      Assigned toNone=>jay
      Open/ClosedOpen=>Closed
    Mon 04 Oct 2010 12:42:35 PM UTCwarp9pnt9Attached File-=>Added md5stat, #21608

    Back to the top


    Powered by Savane 3.1-cleanup1