Saturday 13 September 2014

How to run or execute a program n number of times in a terminal/command line?

If you want to run or execute a program n number of times,you can create a shell script or you can use the native commands provided in the terminal it self.It depends on your convenience.

For example you can use this one

You can use xargs and seq. Generally:

seq nr_of_times_to_repeat | xargs -Iz command
For example:

seq 10 | xargs -Iz xdotool click 1
will execute the xdotool click 1 command for 10 times. 



if you want to use a script

then use this


#!/bin/bash

x=1
while [ $x -le 10 ]
do
  <command to run>
  x=$(( $x + 1 ))
done
where 10 is the number of times to run the command
if you need to build in a little break:
#!/bin/bash

x=1
while [ $x -le 10 ]
do
  <command to run>
  sleep 1
  x=$(( $x + 1 ))
done
Copy the script into an empty file, replace <command to run> by your xdotool command, save it as run_xdotool.sh, run it by the command:
sh /path/to/run_xdotool.sh
Alternatively, you can make it executable and simply run it by
/path/to/run_xdotool.sh

No comments:

Post a Comment