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 8945943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:22:59+00:00 2026-06-15T12:22:59+00:00

I have a shell-script that looks like the following code snippet: … export updates=0

  • 0

I have a shell-script that looks like the following code snippet:

...
export updates=0

processFiles() {
    updates=$((updates+1))
}

export -f processFiles
find $path -exec /bin/bash -c "processFiles '{}'" \;

echo $updates

The use is to count the amount of updates, inserts and files to keep. Unfortunately the last echo always prints 0.

I have already tried to use export in the function as well – didn’t work.

  • 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-15T12:23:00+00:00Added an answer on June 15, 2026 at 12:23 pm

    Instead of using find, you can use bash directly, provided your search criteria are simple enough. E.g.,

    for file in *; do
        processFiles "$file"
    done
    

    will execute the function processFiles on all files and directories of the current directory (except the hidden ones) with argument the name of each file and directory. If you need to apply it recursively to all files and directories and subdirectories (except the hidden ones), use the globstar shell option:

    #!/bin/bash
    
    shopt -s globstar
    shopt -s nullglob
    
    updates=0
    
    processFiles() {
        ((++updates))
    }
    
    for file in **; do
        processFiles "$file"
    done
    
    echo "$updates"
    

    If you just want files, and no directories, insert this in the for loop:

        [[ -f "$file" ]] || continue
    

    which will continue the loop if file is not a file (i.e., if it’s something else, like a directory).

    To match only files in a directory obtained by expanding the variable path, write your for loop thus:

    for file in "$path"/*; do
    

    (or "$path"/** if you’re using globstar and want recursion).

    If you need more complex search criteria, you can always use extglob option. If you need to also include the hidden files, use the dotglob option.

    You’ll find more info about bash in the reference manual, and in particular these sections:

    • Shopt builtin: http://www.gnu.org/software/bash/manual/bashref.html#The-Shopt-Builtin
    • Pattern Matching: http://www.gnu.org/software/bash/manual/bashref.html#Pattern-Matching
    • Conditional Expressions: http://www.gnu.org/software/bash/manual/bashref.html#Bash-Conditional-Expressions

    One last note: If you really don’t like this 100% bash solution and if you still want to do something along the script in your OP, then don’t use bash variables, but use a (temporary) file instead to store the values you need to pass from one process to another. This is a cheap IPC method that works pretty well, but that is more difficult to implement safely.

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

Sidebar

Related Questions

I have a shell script file (run.sh) that contains the following: #!/bin/bash %JAVA_HOME%/bin/java -jar
I have some Perl code that executes a shell script for multiple parameters, to
I have a simple shell script which looks like this: R --vanilla<myMRjob.R hadoop fs
I have a folder organization that looks like this: link.sh dist/MyApp-3.0.0/script.sh dist/MyApp-3.0.0/lib/*.jar The link.sh
I have a php script that looks like this: $contacts[{$firstname}] = $_POST[{$firstname}] ; $contacts[{$lastname}]
Have a shell script that reads the files in a particular directory. #!/bin/bash for
I have a shell script that launches a Maven exec:java process - exec mvn
I have a Bourne Shell script that has several functions in it, and allows
I have a PHP script that I'm invoking from another shell script that sends
I have a shell script, which is run under a opensuse linux, that starts

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.