Site icon Bytefreaks.net

Bash function to execute any command multiple times

Advertisements
#takes 2 parameters:
# 1 - the number of time you can to execute the loop
# 2 - the action to call
# Executes a command multiple times
xloop(){
  ITERATIONS=$1;
  for ((x = 0 ; x <= $ITERATIONS ; x++)); do
    ${*:2}
  done
}

Example use:

xloop 3 date +"%Y-%M-%d"

This post is also available in: Αγγλικα

Exit mobile version