Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 837095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:05:26+00:00 2026-05-15T05:05:26+00:00

I don’t really know that much about bash scripts OR imagemagick, but I am

  • 0

I don’t really know that much about bash scripts OR imagemagick, but I am attempting to create a script in which you can give some sort of regexp matching pattern for a list of images and then process those into new files that have a given filename prefix.

for example given the following dir listing:

allfiles01.jpg allfiles02.jpg
allfiles03.jpg

i would like to call the script like so:

./resisemany.sh allfiles*.jpg 30 newnames*.jpg

the end result of this would be that you get a bunch of new files with newnames, the numbers match up,

so far what i have is:

IMAGELIST=$1
RESIEZFACTOR=$2
NUMIMGS=length($IMAGELIST)

for(i=0; i<NUMIMGS; i++)
  convert $IMAGELIST[i] -filter bessel -resize . RESIZEFACTOR . % myfile.JPG

Thanks for any help…
The parts that I obviously need help with are
1. how to give a bash script matching criteria that it understands
2. how to use the $2 without having it match the 2nd item in the image list
3. how to get the length of the image list
4. how to create a proper for loop in such a case
5. how to do proper text replacement for a shell command whereby you are appending items as i allude to.

jml

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T05:05:26+00:00Added an answer on May 15, 2026 at 5:05 am

    Probably the way a standard program would work would be to take an “in” filename pattern and an “out” filename pattern and perform the operation on each file in the current directory that matches the “in” pattern, substituting appropriate parts into the “out” pattern. This is pretty easy if you have a hard-coded pattern, when you can write one-off commands like

    for infile in *.jpg; do convert $infile -filter bessel -resize 30% ${infile//allfiles/newnames}; done
    

    In order to make a script that will do this with any pattern, though, you need something more complicated because your filename transformation might be something more complicated than just replacing one part with another. Unfortunately Bash doesn’t really give you a way to identify what part of the filename matched a specific part of the pattern, so you’d have to use a more capable regular expression engine, like sed for example:

    #!/bin/bash
    
    inpattern=$1
    factor=$2
    outpattern=$3
    for infile in *; do
        outfile=$(echo $infile | sed -n "s/$inpattern/$outpattern/p")
        test -z $outfile && continue
        convert $infile -filter bessel -resize $factor% $outfile
    done
    

    That could be invoked as

    ./resizemany.sh 'allfiles\(.*\).jpg' 30 'newnames\1.jpg'
    

    (note the single quotes!) and it would resize allfiles1.jpg to newnames1.jpg, etc. But then you’d wind up basically having to learn sed‘s regular expression syntax to specify your in and out patterns. (It’s not that bad, really)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

don't know if the title describes anything about what I'm trying to say but
Don't really know how to formulate the title, but it should be pretty obvious
Don't know much about encryption... Say I'm preparing a SAML request to submit to
Don't know much about running a function on every item in an array, still
Don't know how to google for such, but is there a way to query
Don't know why but font is not displaying.Please help. CSS(in css folder): style.css: @font-face
I don't know why, but this code worked for me a month ago... maybe
Don't know if I worded the question right, but basically what I want to
(Don't know if this is strictly on-topic, but I don't see any better Stack
Don't know how to explain it better but i'm trying to get a response

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.