Print the perl script's path without resolving symlink -
how print script's directory path without resolving symlink?
edit: realized below comment not possible using findbin, there way around script's directory ?
use findbin; use cwd; use cwd 'abs_path'; use file::spec::functions qw( rel2abs ); begin { push @inc, "$findbin::bin"; } print "rel2abs:"; print rel2abs("$findbin::bin"); print "\n"; print "abs_path:"; print abs_path("$findbin::bin"); print "\n";
this script prints:
/tmp/one/two$ perl 3/symlink_to_four/test.pl rel2abs:/tmp/one/two/3/four abs_path:/tmp/one/two/3/four
i want print /tmp/one/two/3/symlink_to_four
/tmp/one/two/3$ ls -l 4 symlink_to_four -> 4
why need this: samba configured in linux box perl script going run, if replace first portion of linux path \\linux-machine-name
, rest of /
\
, windows path, save in file , consumed other script, instance, in above example, trying convert /tmp/one/two/3/symlink_to_four
\\linux-machine-name\one\two\3\symlink_to_four
, know how figure-out linux-machine-name
, don't want resolved path, because cannot figure out windows equivalent path resolved path, \\linux-machine-name\one\two\3\symlink_to_four
valid, not \\linux-machine-name\one\two\3\four
, it's how samba configured.
if correctly understand you're trying achieve, can path::tiny:
#!/usr/bin/perl use strict; use warnings; use path::tiny; $path = path(__file__); print $path->absolute->parent, "\n";
path::tiny's realpath
method resolve symlinks, absolute
method not.
__file__
special token resolves name of perl source file it's contained in (either main script or module loads). use $0
name of script being executed. either of these absolute or relative depending on whether script invoked relative or absolute path.
if scripts invoked absolute path use $0
, not bother module.
Comments
Post a Comment