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 in Linux Administration by Rahul
• 3,380 points
10 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 by Korak
• 5,820 points

Related Questions In Linux Administration

0 votes
0 answers
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
565 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,360 points
791 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,600 points
978 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,360 points
282 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 in Linux Administration by Aditya
• 7,280 points
19 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 in Linux Administration by Korak
• 5,820 points
19 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 in Linux Administration by Korak
• 5,820 points
193 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 in Linux Administration by Korak
• 5,820 points
14 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 in Linux Administration by Korak
• 5,820 points
18 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP