realpath
an example compileAndGo script using C

This compileAndGo C program is a simple wrapper for the realpath system call.

#!/usr/bin/env compileAndGo
# See http://Yost.com/computers/compileAndGo/realpath.html
commandName = realpath
language    = c
!#

#include <stdio.h>
#include <sys/param.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
  int ind;
  int trouble = 0;
  char resolvedPath[MAXPATHLEN];
  // printf("Invoked as %s\n", argv[0]);
  if (argc <= 1) {
    fprintf(stderr, "\nUsage: realpath path ...\n\n"
                    "Echoes real paths one per line.\n"
                    "Exit 1 if any paths fail.\n\n");
    exit(2);
  }
  for (ind = 1; ind < argc; ++ind) {
    if (realpath(argv[ind], resolvedPath) == NULL) {
      fprintf(stderr, "%s: No such path: %s\n", argv[1], argv[ind]);
      trouble = 1;
    } else {
      printf("%s\n", resolvedPath);
    }
  }
  exit(trouble ? 1 : 0);
}


http://Yost.com/computers/compileAndGo/realpath.html - this page
2004-03-03 Created
2005-07-24 Modified to use the new compileAndGo program
2005-07-25 Modified
2005-07-26 Modified with workaround for broken shells
2005-11-06 End the header with !# per compileAndGo 5.0