#!/bin/dash # create 1001 C files, compile and run them # # this program creates 1000 files f0.c .. f999.c # file f$i.c contains function f$i which returns $i # for example file42.c contains function f42 which returns 42 # main.c is created with code to call all 1000 functions # and print the sum of their return values # note use of echo, printf and cat with a here documents create_file() { local n n=$1 # create file$n.c containing function f$n printf "int f%d(void) {\n\treturn %d;\n}\n" "$n" "$n" >"file$n.c" # add declation of function f$n to i.h echo " int f$n(void);" >>i.h # add call to function f$n to main.c echo " v += f$n();" >>main.c # add file$n.c to list of files to compile c_files="$c_files file$n.c" } start_main() { cat >main.c < #include "i.h" int main(void) { int v = 0 ; eof c_files="main.c" } finish_main() { cat >>main.c <