# -*- ch -*- # hello world # print a simple string on stdout puts("Hello World"); # argv # access command line parameters (no segmentation fault accepted, nor silent exception, so some languages must explicitly check the presence of the argument) echo $(_argv[1]); # env # access environment variable echo $HOME # test file exists # return exit code error (non zero) if a file does not exist access("/etc/mtab", 0); # test file readable # return exit code error (non zero) if a file is not readable access("/etc/mtab", 4); # formatting # print integers in a simple formatted string int a=1, b=2; echo $a + $b = $(a+b) # system # call an external program and check the return value if (system("false")) fprintf(stderr, "false failed\n"); system("echo done"); # sed in place # remove #-comments from a file (modifying the file, i.e. in place) char *tmp=tmpnam(NULL); sed 's/#.*//' < $(_argv[1]) > $tmp cp -f $tmp $(_argv[1]) rm -f $tmp # compile what must be # find and compile .c files into .o when the .o is old or absent #include string_t c, o; struct stat cstat, ostat; foreach (c; `find / -name "*.c"`) { o=`echo $c | sed 's/.c$/.o/'`; stat(o, &ostat); stat(c, &cstat); if (ostat.st_mtime > cstat.st_mtime) { echo "compiling $c to $o"; gcc -c -o "$o" "$c"; } }