Batch Convert SVG to PNG

for i in *; do inkscape $i --export-png=`echo $i | sed -e 's/svg$/png/'`; done

By: o0110o
2014-03-24 12:15:58

5 Alternatives + Submit Alt

What Others Think

A few things about your command. It's always a good idea to quote your variables: "$i" Your script will work even if the filenames have whitespace in them. When calling sub-commands, $(...) is better than `...` The $(...) form can be nested, which is useful and also you don't have to escape quote marks. Next, you can use bash to create the output filename (no need for sed), e.g. echo "${i%.png}.svg" Remove ".png" from the end of the variable i (and tack .svg on). echo "${i/.svg/.png}" will also work but it would get confused on file.svg.txt So, a tidier version of your command would look like: for i in *; do inkscape "$i" --export-png="${i%.svg}.png}"; done
flatcap · 407 weeks and 6 days ago
Sorry, I cut'n'pasted incorrectly. That command should have been: for i in *; do inkscape "$i" --export-png="${i%.svg}.png"; done
flatcap · 407 weeks and 6 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: