Reputation: 153
I'm trying to make a shell script that can go through all of the subdirectories in an images/ folder and run a conversion utility from ImageMagick.
I can get the script to work fine in a single folder but can't get the syntax correct to run it from the top directory.
# convert a series of *.png images to *.svg
# images/subfolder1
# images/subfolder2
# etc.
for dir in `ls /*`;
do
for x in `ls -1 /*.png`
do
y=`echo $x | cut -d "." -f1`
echo "convert $x into $y.svg"
convert $x $y.svg
done
done
What would be the correct way to get this done?
Upvotes: 1
Views: 313
Reputation: 3825
By the way the same thing with makefile:
pngs = $(wildcard */*.png)
svgs = $(pngs:.png=.svg)
all: $(svgs)
%.svg: %.png
@echo $@ $^
This also can be run in parallel with make -j
Upvotes: 1
Reputation: 207345
I think you will get far better performance, readability and simplicity using GNU Parallel like this:
find . -name \*.png | parallel convert {} {.}.svg
Why pay for all those lovely Intel cores and only use one of them?
Upvotes: 2
Reputation: 5305
Assuming the script is run from the images
directory:
#!/bin/bash
shopt -s nullglob
for p in */*.png; do
s="${p/.png/.svg}"
echo "converting $p into $s"
# convert "$p" "$s"
done
Upvotes: 0