Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7655647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:33:58+00:00 2026-05-31T12:33:58+00:00

How can I make find apply my shell’s defined functions and aliases inside its

  • 0

How can I make find apply my shell’s defined functions and aliases inside its exec parameter?

For example I have defined a function analogous to bzip2 but using 7z:

function 7zip() { for f in $@; do ls -alF “$f”; 7za a -t7z -m0=lzma
-mx=9 -mfb=64 -md=64m -ms=on “$f.7z” “$f” && touch -r “$f” “$f.7z” && rm -fv “$f” && ls -alF “$f.7z”; done; }

When I find files older than 7 days to compress:

find . -mtime +7  -name "G*.html"   -execdir  7zip {}  + 

Rather than expanding 7zip it errors Command Not Found.

This is all inside a shell script.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T12:33:59+00:00Added an answer on May 31, 2026 at 12:33 pm

    All four of these command works just fine with the function call. Adjust your find specs as need be.. They all cater for spaces in file names. Personally, I can’t see the point of shelling out to another bash instance, but I’ve included two versions which call bash.

    IFS=$'\n'; f=($(find /tmp -maxdepth 1 -name "$USER.*")); f7zipi "${f[@]}"
    
    IFS=; find /tmp -maxdepth 1 -name "$USER.*" | while read -r f ;do f7zipi "$f"; done 
    
    IFS=$'\n'; bash -c 'IFS=; f7zipi "$@"' 0 $(find /tmp -maxdepth 1 -name "$USER.*")  
    
    find /tmp -maxdepth 1 -name "$USER.*" -exec bash -c 'IFS=; f7zipi "$@"' 0 {} +;   
    

    What follows is how I’ve set up the function, using GNU bash 4.1.5 in Ubuntu 10.04

    BTW. You should use local f in your function, so that it does not clash with the calling script’s variable of the same name.

    This is exactly what I added to my ~/.bashrc

    function f7zipi() { 
        local f
        for f in $@; do 
            ls -alF "$f"
            7za a -si -t7z -m0=lzma -mx=9 -mfb=64 \
            -md=64m -ms=on "$f.7z" < "$f" && 
                touch -r "$f" "$f.7z" && 
                rm -fv "$f" && 
                ls -alF "$f.7z"
        done
    }
    export -f f7zipi
    

    When I only assign the above function into a terminal’s bash command line, a script running from that command line fails when it calls the function… If I further apply export -f f7zipi to that same command line.. then the script succeeds… However the scipt only works for that particular commandline session.

    When the function and export are included into ~/bashrc, the script works every time, in any bash session..

    This is the test script

    #!/bin/bash
    f=/tmp/$USER.abc
    g=/tmp/$USER.lmn
    rm -fv "$f" "$f".7z
    rm -fv "$g" "$g".7z
    printf 'abcdefg'>"$f"
    printf 'lmnopqr'>"$g"
    IFS=$'\n'; f=($(find /tmp -maxdepth 1 -name "$USER.*")); f7zipi "${f[@]}"
    exit
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two cmake-related problems: first, I can't make it to find the includes
Problems: to make the picture a coordinate system such that you can apply functions
I have a Blog model that has defined var $hasMany=array(Comment); How can i apply
I can't seem to find the magic combination to make the HeaderStringFormat work for
I can't for the life of me find a way to make this work.
I can't seem to find an answer on this and just want to make
Can someone tell me how I can make the following output? I have a
I often find myself using lambdas as some sort of local functions to make
I want to customize the slider control but can't find any thing to apply,
I can make a DAO recordset in VB6/Access do anything - add data, clean

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.