I wanted to know the "right" way to do this. Basically, I have a list of files that are in an array called current. This is declared as a global variable that looks like this: current=(). I have successfully put all the files in this array. But now, I am going through and parsing arguments to filter out these files and directories.
For example, to implement the -name '*.pattern' command, I pass in the pattern to process_name() which does this:
process_name ()
{
local new_cur=()
for i in "${current[@]}"; do
if [[ "$i" == "$1" ]]; then
new_cur+=("$i")
fi
done
current=( "${new_cur[@]}" )
}
After the loop finishes I want to "clear" my current array. Then I want to loop over the new_cur array, and basically make it equal to current, or if I can, just do something like $current = $new_cur (although I know this won't work).
I've tried doing this after the for loop (in process_name()), but my array current doesn't actually change:
current=( "${new_cur[@]}" )
Is there a good way to do this? Or a right way to do this?