cknight
February 13th, 2008, 03:49 PM
I'm looking for some advice on the design of a bash script I am attempting (slowly!) to write. Here's what I'm trying to do:
1) Execute 'find'
2) Output the result of find to the user with formatted columns (size, date, permissions, path, filename, etc.), one file per line
3) Ask the user "Do you wish to proceed"
4) If yes, then process each file
I first tried using an environment variable:
FIND_OUTPUT=`find ....`
This works, but using "echo $FIND_OUTPUT" doesn't print each file on its own line (unlike the output of the find command), as if all the end-of-line markers had been stripped. And I'd be unsure how to access each file in the variable seperately anyway.
Essentially what I'm looking for is a way to
1) Output the result of the find command to the user as if they had entered that same command on its own (e.g. formatting preserved) (step 2 above)
2) Access each path and filename one by one for processing (in step 4 above)
Two solutions I've thought of involve temporary files (output to a temporary file and then read this file back in) and running the find command twice. Would temporary files be overkill? In regards to running find twice, does anyone know if the result from the first find is cached anywhere or would I be looking at a two-fold increase in script performance time (due to running find twice)?
I realize that find has an -ok flag which allows processing with prompts on each file found, but I want one prompt for ALL files found.
Any help is most appreciated!
1) Execute 'find'
2) Output the result of find to the user with formatted columns (size, date, permissions, path, filename, etc.), one file per line
3) Ask the user "Do you wish to proceed"
4) If yes, then process each file
I first tried using an environment variable:
FIND_OUTPUT=`find ....`
This works, but using "echo $FIND_OUTPUT" doesn't print each file on its own line (unlike the output of the find command), as if all the end-of-line markers had been stripped. And I'd be unsure how to access each file in the variable seperately anyway.
Essentially what I'm looking for is a way to
1) Output the result of the find command to the user as if they had entered that same command on its own (e.g. formatting preserved) (step 2 above)
2) Access each path and filename one by one for processing (in step 4 above)
Two solutions I've thought of involve temporary files (output to a temporary file and then read this file back in) and running the find command twice. Would temporary files be overkill? In regards to running find twice, does anyone know if the result from the first find is cached anywhere or would I be looking at a two-fold increase in script performance time (due to running find twice)?
I realize that find has an -ok flag which allows processing with prompts on each file found, but I want one prompt for ALL files found.
Any help is most appreciated!