mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 07:08:01 +00:00
Add Run A Command Repeatedly Several Times as a Unix TIL
This commit is contained in:
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
|||||||
|
|
||||||
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
||||||
|
|
||||||
_1297 TILs and counting..._
|
_1298 TILs and counting..._
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -1293,6 +1293,7 @@ _1297 TILs and counting..._
|
|||||||
- [Provide A Fallback Value For Unset Parameter](unix/provide-a-fallback-value-for-unset-parameter.md)
|
- [Provide A Fallback Value For Unset Parameter](unix/provide-a-fallback-value-for-unset-parameter.md)
|
||||||
- [Remove A Directory Called `-p`](unix/remove-a-directory-called-dash-p.md)
|
- [Remove A Directory Called `-p`](unix/remove-a-directory-called-dash-p.md)
|
||||||
- [Repeat Yourself](unix/repeat-yourself.md)
|
- [Repeat Yourself](unix/repeat-yourself.md)
|
||||||
|
- [Run A Command Repeatedly Several Times](unix/run-a-command-repeatedly-several-times.md)
|
||||||
- [Safely Edit The Sudoers File With Vim](unix/safely-edit-the-sudoers-file-with-vim.md)
|
- [Safely Edit The Sudoers File With Vim](unix/safely-edit-the-sudoers-file-with-vim.md)
|
||||||
- [Saying Yes](unix/saying-yes.md)
|
- [Saying Yes](unix/saying-yes.md)
|
||||||
- [Search Files Specific To A Language](unix/search-files-specific-to-a-language.md)
|
- [Search Files Specific To A Language](unix/search-files-specific-to-a-language.md)
|
||||||
|
|||||||
17
unix/run-a-command-repeatedly-several-times.md
Normal file
17
unix/run-a-command-repeatedly-several-times.md
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
# Run A Command Repeatedly Several Times
|
||||||
|
|
||||||
|
From the terminal in a Bash or Zsh shell session, I can loop on a command to
|
||||||
|
have it run a specific number of times.
|
||||||
|
|
||||||
|
If I want to run a test command (e.g. `bin/test some_file.spec:123`) 12 times
|
||||||
|
in a row, I could use a for loop like so:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
for i in {1..12}; do bin/test some_file.spec:123; done
|
||||||
|
```
|
||||||
|
|
||||||
|
And the shell will run the command one time after another until it has been run
|
||||||
|
12 times. That range `{1..12}` can be adjusted to whatever I want. For
|
||||||
|
instance, to have it loop 3 times, I'd make it into `{1..3}`.
|
||||||
|
|
||||||
|
[source](https://serverfault.com/questions/273238/how-to-run-a-command-multiple-times-using-bash-shell)
|
||||||
Reference in New Issue
Block a user