Sid Sid - 4 months ago 8
Bash Question

Bash script to process all files in folder and save all output in different folder with same file names?

I am writing a script to change size of svg images. Here is what I am trying

#!/bin/bash
for file in *
do
rsvg-convert "$file" -w 160 -h 160 -f svg -o `echo $i | sed -e 's/svg$/new.svg/'`
done


But this is not working.

Answer

Use bash substitition directly (${file%.svg} will remvoe .svg from the end of file variable):

#!/bin/bash
mkdir -p folder
for file in *
do
  rsvg-convert "$file" -w 160 -h 160 -f svg -o folder/${file%.svg}new.svg 
done