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

  • SEARCH
  • Home
  • 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 875491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:16:45+00:00 2026-05-15T11:16:45+00:00

Hi I am a newbe to bash programming and need some help. I am

  • 0

Hi I am a newbe to bash programming and need some help. I am building a pipeline for image processing. I would like to be able to take the png images in a folder and pass them to clusterImage.pl once that is done I would like to then pass the outputted file to seperateObjects.pl the outputted file is of the same name but has kmeansOutput.all.matrix attached to the end. Below is what I have so far, but it is not working.
Any help would be greatly appreciated. Thank you

#!/bin/bash
#This script will take in an image and a matrix file.
#The output will be an image and a matrix file.

list=`ls *.png`
for i in $list
do
$file="./$list"
$image_array = $list
echo $file
#Cheching to see if the file exists.
for((j=0;j<=i;j++))
do
if [ -e image_array[j] ]; then
echo $file
echo "Begining processing"
#Take in an image and create a matrix from it.
perl clusterImage.pl SampleImage.png
#Take in a matrix and draw a picture showing the centers of all
#of the colonies.
perl seperateObjects.pl SampleImage.png.kmeansOutput.all.matrix
echo "Ending processing"
else
echo "There is an issue"
fi
done
done
  • 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-15T11:16:46+00:00Added an answer on May 15, 2026 at 11:16 am

    I see a few problems (or potential improvements) with your code:

    1. You don’t need the loop for i in $list because you never use $i in the script – that results in just doing the same thing over and over again (the same number of times as the number of .png files in the directory)
    2. You don’t need to use a Bash array, since Bash can iterate over the different filenames in a list like *.png.
    3. I suspect you mean to run perl clusterImage.pl on each .png file in the directory… or did you? It’s kind of hard to tell. Edit your question to explain more clearly what you mean to do, and I can edit my answer accordingly.
    4. You can use short-circuiting, as they call it, instead of an if statement: [ -f file.png ] && echo "file exists" is shorter than

      if [ -f file.png ]; then
          echo "file exists"
      fi
      

    If I understand what you’re trying to do (and I’m not sure I do), I think this might work for you. For each image in the directory, this will run perl clusterImage.pl <name_of_image.png> and perl separateObjects.pl <name_of_image.png>.kmeansOutput.all.matrix.

    for image in *.png
    do
      [[ -f $image ]] && perl clusterImage.pl $image && perl separateObjects.pl $image.kmeansOutput.all.matrix
    done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

BeautifulSoup newbe... Need help Here is the code sample... from mechanize import Browser from
Newbie question: some vendors propose solution like generating dynamic certificates to allow user who
I just saw some code in bash that I didn't quite understand. Being the
I'm trying to write a bash script which would locate a single file in
This is part of my code for login, I would like to logout users
I'm a newbie in bash scripts and have the following problem : I'm trying
#!/bin/bash echo 'first line' >foo.xml echo 'second line' >>foo.xml I am a total newbie
newbie here, so thanks in advance for help! I have a Wordpress site with
I newbie in bash scripting but i don't uderstand why it's not work #!/bin/bash
I am a newbie to BASH so please dont mind my stupid questions because

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.