How can I select files one by one from a list and work on them? This is my code:
list=$( find $path \( -name "*.c" -or -name "*.cpp" -or -name "*.cxx" -or -name "*.cc" \) )
for file in "$list"
do
done
How can I select files one by one from a list and work on them? This is my code:
list=$( find $path \( -name "*.c" -or -name "*.cpp" -or -name "*.cxx" -or -name "*.cc" \) )
for file in "$list"
do
done
You can pass to find
as many commands as you like:
find $path \( -name "*.c" -or -name "*.cpp" -or -name "*.cxx" -or -name "*.cc" \) \
-exec bash -c "echo cmd1 '{}'; echo cmd2 '{}'; echo etc." \;
an alternative is to write a function:
function safe_copy() {
echo "$1"
}
export -f safe_copy
find $path \( -name "*.c" -or -name "*.cpp" -or -name "*.cxx" -or -name "*.cc" \) \
-exec bash -c "safe_copy '{}'" \;
You can also write a script and call it with exec instead of a function.
You can use -print0
as find
argument, to print a null
delimited stream of filenames.
Then loop read the null
delimited stream.
find "$path" \( -name '*.c' -or -name '*.cpp' -or -name '*.cxx' -or -name '*.cc' \) -print0 |
while IFS= read -r file
do
done