Reputation: 11107
I do the most basic thing in every script
SCRIPT=`readlink -f ${0}`
HOME=`dirname $SCRIPT`
and, given $0 = C:\Users\dir\file
, readlink
gives me /cygdrive/c/CURRENT_DIRECTORY/C:\Users\dir\file
so that the next dirname
produces terrible /cygdrive/c/Users/CURRENT_DIRECTORY/C:\Users\dir
instead of C:\Users\dir
or /cygdrive/c/Users/dir
Is it supposed to work this way?
Upvotes: 2
Views: 1625
Reputation: 605
readlink in cygwin (Windows 7) is driving me crazy. The same code works, then doesn't work, from moment to moment, with no changes to the input data. Mostly it doesn't work now (May 2013). It worked in January 2013.
$ ln -s foo bar
$ perl -e 'print readlink("/cygdrive/C/bin/bar")'
foo
but try that in a running program and it doesn't always work. readlink(`cygpath $file`) worked the first time I ran it, but on immediately re-running the program, it could no longer read the same $file and returned undef.
I'm currently using this horrible kludge. It works, but I hate it:
if (-l $file) {
my $real = readlink($file);
if (!$real) {
# KLUDGE FOR CYGWIN
my $cmd = "perl -e 'print readlink(\"$file\")'";
$real = `$cmd`;
die "ERR: No link for link $file date=$fileDate" unless $real;
Upvotes: 2
Reputation: 11107
It seems that I have found the answer: we should convert $0
into cygwin format then readlink
can work with it
ZERO=`cygpath ${0}`
SCRIPT=`readlink -f ${ZERO}`
Upvotes: 5