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

  • Home
  • SEARCH
  • 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 8791789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:53:28+00:00 2026-06-13T22:53:28+00:00

I write a bash script: #!/bin/bash function test_echo { echo $0 echo $1 echo

  • 0

I write a bash script:

   #!/bin/bash
    function test_echo
    {
        echo $0
        echo $1
        echo $2
        echo $#
    }
    test_echo

I try:

find test.sh -type f -exec test_echo '{}' \;

or

find . -type f -exec `./test.sh {}` \;

but it doesn’t work.

I need a way to scan file from a folder (I use find) and for each file call a function ( foo_fonction() ) with in parameter the full path of the file.

 find . -type f -exec foo_fonction '{}' \; 

And how to have the parameter (full path) in the foo_fonction() ?

  • 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-06-13T22:53:29+00:00Added an answer on June 13, 2026 at 10:53 pm

    There are 2 ways to go about this:

    1: You can put either put the function definition as part of your find files script:

    (Let’s call this find_stuff.sh)

    #!/bin/bash
    
    test_echo() {
        echo $0
        echo $1
        echo $2
        echo $#
    }
    
    files=$(find $(pwd) -type f)
    for f in $files
    do
        test_echo "$f"
    done
    

    Explanation of what this does:

    • A new shell is spawned to run this script if you do ./find_stuff.sh
    • First it defines the test_echo() function,
    • Then it finds all of the files under the current working directory recursively
    • Note that since we specified $(pwd) as the search directory, which will be an absolute path, the results returned by find will be absolute paths too – as you desired.
    • Then for each of these files, pass its file path to the test_echo function

    2: Put the function definition elsewhere, but you still want a find_stuff.sh script:

    #!/bin/bash
    
    files=$(find $(pwd) -type f)
    for f in $files
    do
        ./test.sh "$f"
    done
    

    and test.sh should look like this:

    #!/bin/bash
    
    test_echo () {
        echo $0
        echo $1
        echo $2
        echo $#
    }
    
    test_echo $@
    

    Note the last line test_echo $@ – the $@ part is what you were missing before.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a bash script. I want to find files by
Let's say I've got a shell script called print_error.sh looking like this: #!/usr/bin/bash echo
I'm trying to write a helper function to use in a bash script to
http://bash.cyberciti.biz/file-management/shell-script-to-simulate-unix-more-command/ #!/bin/bash # Write a shell script like a more command. It asks the
I'm trying to write a bash script that will recursively search a directory, find
I have a bash script which calls another bash script, like so: #!/bin/bash echo
I'm trying to write a bash script in CentOS that tests the various echo
I wrote a bash script to start thin server for two projects. #! /bin/sh
following is the bash script I wrote for Sqlite. #!/bin/bash sqlite3 file.db CREATE TABLE
I have to write a bash script that makes lot of things. I'd like

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.