in reply to Getting the shell's version of working directory, without PWD's help
There are a number of modules that return an absolute path without resolving anything.
use Path::Tiny qw( path ); my $abs = path($0)->absolute;
For example, launching the script using ./a.pl or perl a.pl from /home/ikegami/foo would result in /home/ikegami/foo/a.pl.
But note that launching the script using ../bar/a.pl or perl ../bar/a.pl from /home/ikegami/foo would result in /home/ikegami/foo/../bar/a.pl. That's because /home/ikegami/foo/../bar/a.pl can't be safely reduced to /home/ikegami/bar/a.pl because /home/ikegami/foo might be a symlink.
Seeking work! You can reach me at email@example.com
|Replies are listed 'Best First'.|
Re^2: Getting the absolute path of a script, without PWD
by perlancar (Hermit) on Jul 15, 2021 at 23:57 UTC