You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Custom terminal command: repeat a command a number of times
Joel Meador edited this page Jun 8, 2026
·
1 revision
Why would you need such a thing?
Well in my case there are tests that fails about 5-10% of the time and I wanted to be able to run those tests a bunch of times to see if my fix changed the failure rate to 0 or at least statistically lower.
Another thing to glean from this is the use of $@, which is equivalent to "all the arguments to the command except the command itself ($0 AKA tentimes/hundredtimes) in this case. This is so it can execute in this example mix test test/web/views/shared_view_test.exs, which when split on strings in this context are also $1, $2, $3
#!/usr/bin/env zsh
function tentimes() {
for i in {1..10}; do "$@"; done
}
function hundredtimes() {
for i in {1..100}; do "$@"; done
}
Or add the above functions to .bashrc or .zshrc
So you can just run:
tentimes mix test test/web/views/shared_view_test.exs
or
hundredtimes mix test test/web/views/shared_view_test.exs