Skip to content

Commit fd947a5

Browse files
committed
Add Run A Command Repeatedly Several Times as a Unix TIL
1 parent c2e4a29 commit fd947a5

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
1010

1111
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
1212

13-
_1297 TILs and counting..._
13+
_1298 TILs and counting..._
1414

1515
---
1616

@@ -1293,6 +1293,7 @@ _1297 TILs and counting..._
12931293
- [Provide A Fallback Value For Unset Parameter](unix/provide-a-fallback-value-for-unset-parameter.md)
12941294
- [Remove A Directory Called `-p`](unix/remove-a-directory-called-dash-p.md)
12951295
- [Repeat Yourself](unix/repeat-yourself.md)
1296+
- [Run A Command Repeatedly Several Times](unix/run-a-command-repeatedly-several-times.md)
12961297
- [Safely Edit The Sudoers File With Vim](unix/safely-edit-the-sudoers-file-with-vim.md)
12971298
- [Saying Yes](unix/saying-yes.md)
12981299
- [Search Files Specific To A Language](unix/search-files-specific-to-a-language.md)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Run A Command Repeatedly Several Times
2+
3+
From the terminal in a Bash or Zsh shell session, I can loop on a command to
4+
have it run a specific number of times.
5+
6+
If I want to run a test command (e.g. `bin/test some_file.spec:123`) 12 times
7+
in a row, I could use a for loop like so:
8+
9+
```bash
10+
for i in {1..12}; do bin/test some_file.spec:123; done
11+
```
12+
13+
And the shell will run the command one time after another until it has been run
14+
12 times. That range `{1..12}` can be adjusted to whatever I want. For
15+
instance, to have it loop 3 times, I'd make it into `{1..3}`.
16+
17+
[source](https://serverfault.com/questions/273238/how-to-run-a-command-multiple-times-using-bash-shell)

0 commit comments

Comments
 (0)