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

 
 

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

Submitter:  Leif W <warp9pnt9>
Submitted:  Mon 04 Oct 2010 12:42:35 PM UTC
   
 
Category:  find Severity:  3 - Normal
Item Group:  Wrong result Status:  Invalid
Privacy:  Public Assigned to:  jay
Originator Name:  Open/Closed:  Closed
Release:  4.4.2 Fixed Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

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>
Group administrator
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 Files:
   
   
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
  • -email is unavailable- added by jay (Posted a comment)
  • -email is unavailable- added by warp9pnt9 (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2010-10-05 jay StatusNone Invalid
        Assigned toNone jay
        Open/ClosedOpen Closed
    2010-10-04 warp9pnt9 Attached File- Added md5stat, #21608

    Back to the top

    Powered by Savane 3.13-bb6a.
    Corresponding source code