0

I have a C program ./myProgram 1 (where 1 is the argument fixed) in the directory

gianni@mylinux:~/myWork/myApplication$ ./myProgram

I wish to run this C program 100 times using a loop insted a very not elegant solution to copy 100 times the line gianni@mylinux:~/myWork/myApplication$ ./myProgram in a shell script

  • Is the argument always 1, or should that increment, or...? – Jeff Schaller Aug 20 '18 at 22:51
  • not it's fixed. Just 1 – Gianni Spear Aug 20 '18 at 22:51
2

Write on the command line:

i=0; while [ $((i+=1)) -le 100 ]; do ./myProgram 1; done

Assuming your IFS does not have numbers in it, or just quote as "$((i+=1))"

Or (with ksh, bash, zsh)

for i in {1..100}; do ./myProgram 1; done
1

This should be easily accomplished using the following script:

#!/bin/sh
for i in $(seq 1 100); do
  ./myProgram 1
done

Or with a one-liner version:

for i in $(seq 1 100); do ./myProgram 1; done

  • There is the (small) chance that IFS could remove some numbers from the (unquoted) expansion of seq. – Isaac Aug 20 '18 at 23:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.