Tux


Bash: Problem with reading files with spaces in the name using a for loop

Recently we were working on a bash script that was supposed to find and process some files that matched certain criteria. The script would process the files one by one and the criteria would be matched using the find command. To implement our solution, we returned the results of the find back to the for loop in an attempt to keep it simple and human readable.

Our original code was the following:
(do not use it, see explanation below)

for file in `find $search_path -type f -name '*.kml'`; do
  # Formatting KML file to be human friendly.
  xmllint --format "$file" > "$output_path/$file";
done

Soon we realized that we had a very nasty bug, the way we formatted the command it would break filenames that had spaces in them into multiple for loop entries and thus we would get incorrect filenames back to process.

To solve this issue we needed a way to force our loop to read the results of find one line at a time instead of one word at a time. The solution we used in the end was fairly different than the original code as it had the following significant changes:

  • the results of the find command were piped into the loop
  • the loop was not longer a for loop and a while loop was used instead
  • it used the read command that reads one line at a time to fill in the filename variable
    (the -r parameter does not allow backslashes to escape any characters)

Solution

find $search_path -type f -name '*.kml' | 
while read -r file; do
  # Formatting KML file to be human friendly.
  xmllint --format "$file" > "$output_path/$file";
done


Neural Style Transfer – Mosaic Style Source

We are looking for the source of the mosaic style for neural style transfer, we came across the following image that was apparently used by several people as input but we could not identify the source of it.

The photo depicts a lady holding a flower on stained glass.

(c) copyright 2006, Blender Foundation / Netherlands Media Art Institute / www.elephantsdream.org
This an audio-less re-production of the “Elephants Dream” by Blender Foundation after it was parsed using a neural network that attempts to transfer the same style as a photo that depicts a lady holding a flower on stained glass (https://bytefreaks.net/photography/neural-style-transfer-mosaic-style-source). We do not know the origin of this art yet…
Audio will be added at a later stage.

Neural Style Transfer – Feathers Style Source

While looking for the source of the Feathers style for neural style transfer we came across the following image that was apparently used by several people as input.

After some special Google-Fu we were able to find a page that posts the above watercolor paint with feathers leaves and petals which states that the painter is Kathryn Corlett.

This an audio-less re-production of the “Elephants Dream” by Blender Foundation after it was parsed using a neural network that attempts to transfer the same style as what seems to be the work named “Feathers Leaves and Petals” by Kathryn Corlett to each frame of the video.
Audio will be added at a later stage.