Is there a better way to run a command N times in bash

0 votes

I occasionally run a bash command line like this:

n=0; while [[ $n -lt 10 ]]; do some_command; n=$((n+1)); done

To run some_command a number of times in a row -- 10 times in this case.

Often some_command is really a chain of commands or a pipeline.

Is there a more concise way to do this?

Jun 13, 2022 in Linux Administration by Rahul
• 3,380 points
726 views

1 answer to this question.

0 votes
In the event that your reach has a variable, use seq, similar to this:

count=10
for I in $(seq $count); do
    order
done
Basically:

for run in {1..10}; do
  order
done
Or on the other hand as a joke, for those that need to reorder without any problem:

for run in {1..10}; do order; done
answered Jun 13, 2022 by Korak
• 5,820 points

Related Questions In Linux Administration

0 votes
0 answers

Is there a way to determine the amount of free video RAM in Linux?

We believe that we are running out ...READ MORE

Apr 26, 2022 in Linux Administration by Edureka
• 13,690 points
426 views
0 votes
1 answer

What is the linux command to find Memory and CPU usage in percent for last 30 days?

Try the following: Cat proc/meminfo top top -i less /proc/memin ...READ MORE

answered Oct 14, 2020 in Linux Administration by Kim
2,532 views
0 votes
1 answer

How to run one command inside another command in Linux?

Hi@akhtar, You can run multiple commands in your ...READ MORE

answered Oct 15, 2020 in Linux Administration by MD
• 95,460 points
3,056 views
0 votes
1 answer

How to create nested directories with a single command in linux?

Try this command. mkdir -p /parent_dir/son_dir READ MORE

answered Oct 19, 2020 in Linux Administration by anonymous
• 19,610 points
2,222 views
0 votes
1 answer

How to find the first field from a file in Bash Shell?

Hi@akhtar, You can extract text from a file. ...READ MORE

answered Oct 20, 2020 in Linux Administration by MD
• 95,460 points
1,093 views
0 votes
0 answers

How to convert a PDF into JPG with command line in Linux?

What are fast and reliable ways for ...READ MORE

Apr 14, 2022 in Linux Administration by Aditya
• 7,680 points
587 views
0 votes
1 answer

How to check if a string contains a substring in Bash?

You ought to recollect that shell prearranging ...READ MORE

answered May 27, 2022 in Linux Administration by Korak
• 5,820 points
1,235 views
0 votes
1 answer

Windows system, after heroku login from git bash, there is no command line show

You can login via Windows command prompt ...READ MORE

answered May 27, 2022 in Linux Administration by Korak
• 5,820 points
1,605 views
0 votes
1 answer

Is there a better way to run a command N times in bash?

In the event that your reach has ...READ MORE

answered Jun 16, 2022 in Linux Administration by Korak
• 5,820 points
538 views
0 votes
1 answer

Is there a limit on the number of words in bash command 'for file in words'?

Anyway, you need to print everything except ...READ MORE

answered May 27, 2022 in Linux Administration by Korak
• 5,820 points
662 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP