amit
amit

Reputation: 39

How to use a function for a simultaneously run process in bash?

#!/bin/bash

function func_name {
do something
}

find . -name "*" -type d -exec bash -c '( cd {} &&

func_name;

)' bash $1 $2 {} \;

$1 and $2 are commandline arguments unrelated to the question asked I believe. I am trying to go to all sub-directories and run a function, but I get a message "func_name: command not found"

Upvotes: 1

Views: 55

Answers (1)

Patrick Trentin
Patrick Trentin

Reputation: 7342

In your code, func_name is invoked within a sub-shell with a totally new environment, thus you should export it first:

#!/bin/bash

function func_name {
do something
}

export -f func_name

find . -name "*" -type d -exec bash -c '( cd {} &&

func_name;

)' bash $1 $2 {} \;

Upvotes: 2

Related Questions