I’ve got two arrays in my bash, each containing files. In my loop, sometimes a file gets deleted. Whenever that happens, one of the arrays shows the old state, the other one shows the new state. How do I manage to show the difference between them, e. g. which file exactly got deleted? By the way, there is no other way to find out.
Here’s an example:
arr_a=( file1.txt file2.txt file3.txt )
arr_b=( file1.txt file3.txt )
#Now the output should be file2.txt
I imagined something lile echo ${arr_a[@]#arr_b[@]}, but this didn’t work. (This results in arr_a being output entirely.)
This one is a bit complicated but will work in the case the arrays don’t maintain correlativity. It sorts all elements of the larger array to correlate to those in the shorter array, and then prints the remaining elements in the larger array (it works on copies of the arrays). Not fully tested: