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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:14:40+00:00 2026-06-07T04:14:40+00:00

I would like to write a bash script in Linux that executes a program

  • 0

I would like to write a bash script in Linux that executes a program multiple times (e.g., 3 times) and that specifies a switch value based on a list of values provided in a text file.

For example, suppose that there is some program programname that has a switch -switch that takes a floating point number as input. So, one execution of the program might read:

programname -switch 0.05

where 0.05 is a particular value passed to the switch -switch.

Now I would like to read in some sort of text file that has a list of values that I would like to pass, in succession, to -switch in separate calls of programname. My text file test.txt might contain these data:

0.05
3.19
100.75

I would like to write a bash script that will read in the text file and effectively make these calls in succession:

programname -switch 0.05
programname -switch 3.19
programname -switch 100.75

I am thinking of something like this:

#!/bin/bash
for i in {1..3}
do
programname -switch $x
done

But, what should I type in place of $x? In other words, I am not sure how to read in test.txt and provide its contents, one-by-one, to -switch as the for loop runs. Do you have any advice? Thank you!

  • 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-06-07T04:14:42+00:00Added an answer on June 7, 2026 at 4:14 am

    values.txt:

    0.05
    3.19
    100.75
    

    script.sh:

    #!/bin/bash
    
    counter=1
    for value in $(cat values.txt)
    do
        programname -switch $value -counter $counter
        counter=$(expr $counter + 1)
    done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to write a bash script or a few shell commands that
I would like to write a bash script that prints out the date in
I would like to write a query that returns a single date value, that
I'm trying to write (what I thought would be) a simple bash script that
I'm trying to write a bash script that would modify all occurrences of a
I am new to bash scripting and would like to write a bash script
I would like to write the a startup script in bash to make an
I'd like to write a Bash script that reports a sum. I'm starting with
I would like to write the following Bash Script: When installing LAMP like this,
I would like to write a script that installs JAGS and rjags on a

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.