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 7058667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:08:24+00:00 2026-05-28T04:08:24+00:00

I have a number of bash scripts. for example script1_1.sh script1_2.sh script1_3.sh etc…. I

  • 0

I have a number of bash scripts. for example

script1_1.sh
script1_2.sh
script1_3.sh

etc….

I was wondering, is there a way for me to run these all in another script. where by I don’t have to manually add each. So through the use of a for loop? where it increments a number like

for (i=0; i < 40; i++)
   ./script1_[i].sh

I would also like to check each script worked, so if not, it would exit the for loop.

if ./script[i] (command unsuccessful)
then break?

Can anyone help me write this code? i’m very new to scripting languages.

  • 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-28T04:08:25+00:00Added an answer on May 28, 2026 at 4:08 am

    You are really close to answering your own question. The C-style for loop will work fine for your scenario, but if your scripts are randomly named, you can use an array. You can use ||, which will execute the right side if a non-zero exit status is returned. You could also use an if statement like you have proved in your question, with a “!” between if in the command (if not).

    scripts=( script1_1.sh script1_2.sh script1_3.sh )
    
    for script in "${scripts[@]}"; do
       ./"$script" || { echo "$script failed"; break; }
    done
    

    Using the for loop like in your questions:

    for ((i=1;i<4;i++)); do
       ./script1_${i}.sh || { echo "$script failed"; break; }
    done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a number of bash scripts which invoke R scripts for plotting things.
I have a number of shell scripts that all look like this: #!/bin/bash cd
Are there any scripts, libraries, or programs using Python , or BASH tools (e.g.
I have a bash scripts which an argument enclosed with double quotes, which creates
I have a Bash shell script that invokes a number of commands. I would
I have a bash script that basically should work like below: get build number
I have a little Bash script which suspends the computer after a given number
I'm working on a project were we have number (5 at the moment) of
I have a number of macros written for Visual Studio 2005, but they have
I have a number of tracks recorded by a GPS, which more formally can

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.