I need the right syntax to copy file.jpg 100 times with one command so to get
100 files named file001.jpg, file002.jpg, …, file100.jpg.
I’m using this but not working for me
any tips
#!/bin/bash
for x in `seq 1 100`; do
if [[ x -lt 10 ]]; then cp file.jpg file-00$x.jpg;
elif [[ x -lt 100 ]]; then cp file.jpg file-0$x.jpg;
else cp file.jpg file-$x.jpg;
fi
done
In your two
ifconditions, you’re missing the$on$x, so you’re ending up comparing the stringx, rather than the number.As Basile Starynkevitch notes, though, the
printfutility is probably a much better way to go here:$(printf "file-%03d.jpg" $x)gets you the right formatted string in a single line.