use internal function with find command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting use internal function with find command
# 1  
Old 08-12-2010
use internal function with find command

Hi,

I need to use a function in the find command to do some process on the file. I'm trying:
Code:
funcname(){ ... }
...
find ./ -name "*" -exec funcname {} \;

But somehow this is not working. I don't want to have a separate script for whatever processing the function does. I want to have both the function and the find command in the same script.

Is there anyway I can put both of them in the same script.

Thanks.
Victor

Moderator's Comments:
Mod Comment Use code tags, ty.
# 2  
Old 08-12-2010
-exec of find and xargs expect an executable, a command, not a shell script function afaik. So maybe you assign the output of the find to some variable and hand it over as positional parameter for your function instead.

Example:
Code:
myfunc()
{
        echo "This is it: $*"
}

VAR=`find . -type f -print`

myfunc $VAR

This User Gave Thanks to zaxxon For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

How to find which internal hosts still using my DNS service ? Please help

Hello guys, I am new to AIX . I have two AIX v5.3 servers running BIND DNS service on them. The plan is to shut down only the DNS service on them, but in order to do that I have to determine which internal hosts are still using the servers to resolve DNS queries. Can you please advice on... (2 Replies)
Discussion started by: tihomirvs
2 Replies

2. UNIX for Advanced & Expert Users

BASH Internal : Replace pattern with string without external command

Morning, I'm trying step up my scripting game .. :rolleyes::confused::D Is there a way to do the replacement with an or without using an external command ? I did try but no joy. var=${var//\(|\)/} #!/bin/bash var="lulus.UbiRwidgets.com (10.1.1.1)" var=${var//\(/}... (5 Replies)
Discussion started by: popeye
5 Replies

3. Shell Programming and Scripting

find function

Hi, There is requirement where I need to search if a particular directory name is present or not and if its present I need to collate the paths of the directories in a file. I tried the below command echo $(find /home/mqm -name "check")>>config.txt Its saving the paths in one line(like... (7 Replies)
Discussion started by: jayii
7 Replies

4. Shell Programming and Scripting

for loop with internal unix command in statement throwing error

Hi I've gotten a plugin script that won't run. I keeps throwing an error at the following line. for BARCODE_LINE in `cat ${TSP_FILEPATH_BARCODE_TXT} | grep "^barcode"` do #something done The error reads ... (3 Replies)
Discussion started by: jdilts
3 Replies

5. Shell Programming and Scripting

Call function from Find command

I am writing a bash script in which I am using the find command to find files, and then I'd like to send the output to a function (in the same script) that will process those results (such as test if the file is an image, and other things). However, try as I might, I can't get the function to... (6 Replies)
Discussion started by: twjolson
6 Replies

6. Shell Programming and Scripting

awk: Internal software error in the tostring function on

Hello, I posted a working script on this thread: https://www.unix.com/emergency-unix-linux-support-help-me/160123-help-make-awk-script-more-efficient-large-files.html When I run this script on a large file, 351 MB I get this error: awk: Internal software error in the tostring function on... (8 Replies)
Discussion started by: script_op2a
8 Replies

7. Shell Programming and Scripting

Internal software error in the tostring function for files greater than 300 MB

Hello, When I run my awk script with input files greater than 300 MB I always get this error: awk: Internal software error in the tostring function on TS1101?05044400?.0085498227?0?.0011041461?.0034752266?.00397045?0?0?0?0?0?0?11/02/10?09/23/10???10?no??0??no?sct_det3_10_20110516_143936.txt ... (0 Replies)
Discussion started by: script_op2a
0 Replies

8. UNIX for Advanced & Expert Users

Forwarding internal internet packets to internal webserver using iptables

Hi, I need to redirect internal internet requests to a auth client site siting on the gateway. Currently users that are authenticated to access the internet have there mac address listed in the FORWARD chain. All other users need to be redirected to a internal site for authentication. Can... (1 Reply)
Discussion started by: mshindo
1 Replies

9. Shell Programming and Scripting

using awk to drive an internal function

I have a piece of script that needs to pull every element in column 2 from a file of varying size. Rather than writing something to read the file and then pass the data line by line to my script, I want to use awk. However, what is the correct syntax to get awk to call a function (named via: ... (7 Replies)
Discussion started by: quaddriver
7 Replies

10. UNIX for Dummies Questions & Answers

Mail fail to find internal server

I am getting a "connection to the server has failed" error when trying send out internal email. this will be like this for maybe four hours then it will start working for no reason. then it will stop again. the only constant i have is if i reboot the server the send mail will work for about an... (1 Reply)
Discussion started by: jrblanton
1 Replies
Login or Register to Ask a Question