Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

In: for i in temp/*; do when I use i it contains the path temp/ and I do not want this?

I have the magick absolute in a folder and in a sub-folder temp I have images. I need/want to process the images and write them to another sub-folder output.

folder (with magick)
    temp sub-folder (with input files)
    output sub-folder (where processed images are placed)

But I am unable to stop the variable i picking up the path temp/. How do I stop it? Do I have to strip the characters temp/ from i then use it? Or is there a simple way to do this?

for i in temp/*; do
    ./magick convert -resize 450 -strip -quality 90% temp/$i output/$i
done

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Yes you can with parameter expansion:

shopt -s nullglob

for i in temp/*; do
    ./magick convert -resize 450 -strip -quality 90% "$i" "output/${i#temp/}"
done

The nullglob prevents 0 matches from expanding to the pattern.

Maybe you can also just change working directory to temp and use ... I’m just not sure if magick will still work if referred from a different directory.

cd temp || exit

for i in *; do
    ../magick convert -resize 450 -strip -quality 90% "$i" "../output/$i"
done
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading