Skip to content

Instantly share code, notes, and snippets.

@alexjaw
Created August 12, 2020 11:54
Show Gist options
  • Save alexjaw/919deb9cb8519d4e44de8d23dfdec6e7 to your computer and use it in GitHub Desktop.
Save alexjaw/919deb9cb8519d4e44de8d23dfdec6e7 to your computer and use it in GitHub Desktop.
How to repeat a cmd using bash
#! /usr/bin/env bash
# Example
# $ ./repeat.sh 2 date 1
# i = 2
# c = date
# s = 1
i=$1 # iterations
c=$2 # cmd to run
s=$3 # sleep time
for ((n=1; n<=$i; n++))
do
echo "test" $n "cmd =" $c
$c
sleep $s
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment