symbolic link question
    Michael O'Donnell 
    mod+gnhlug at std.com
       
    Tue Dec  3 15:37:00 EST 2002
    
    
  
While solving a related problem I ended up writing the
following little program that might be of interest to you:
#include <stdio.h>
#include <string.h>
/*
 * ----------------------------------------------------------------------------
 * Read lines from stdin, assume they're pathnames, attempt
 * to convert them to their "canonical" form, print canonical
 * version if successful else just echo unconverted input.
 */
int
main(
    int    argc,
    char **argv  )
{
    char   pathname[  102400 ];
    char   canonical[ 102400 ];
    char  *ptr;
    while( fgets( pathname, (sizeof( pathname ) - 1), stdin )  )  {
        if( (ptr = strchr( pathname, '\n' ))  )  {
            *ptr = 0;
        }
        printf( "%s\n", realpath( pathname, canonical )? canonical: pathname );
    }
    return( 0 );
}
...which (after saving that source code in a file
named canonicalPath.c) you might be able to use thus:
   gcc -o ~/bin/canonicalPath canonicalPath.c
   ln -s /tmp myLocalTMPsymlink
   cd `echo myLocalTMPsymlink | ~/bin/canonicalPath`
   pwd
...and of course you could then redefine your 'cd'
command as a function:
   function cd()  {
      builtin cd `echo $1 | ~/bin/canonicalPath`
   }
...which would allow you to just use your 'cd'
command as always.
    
    
More information about the gnhlug-discuss
mailing list