1

I tried googling, but I found only additional packages handling this (which I would like to avoid for various reasons).

In Lua5.3, is there some way to resolve a symlink, possibly recursively, using just the standard library?

I'm looking for something equivalent to:

lua -lfs -e 'print(fs.realink("/proc/self/exe"))'

... only I don't have "fs" (and required "path") on my target.

Any way implementing this in pure lua using just the standard lib?

ZioByte
  • 2,690
  • 1
  • 32
  • 68

1 Answers1

1

In Lua 5.3 i use...

cmd=function(cmd)
cmd=io.popen(cmd, 'r')
cmd = cmd:read('a+')
return cmd
end

...for storing output of external commands in a Lua variable. An example for using it...

erg=cmd('file /proc/self/exe|grep -o -E "[/a-z]{1,512}$"')
print(erg)

But io.popen() is not available on all Lua 5.3 environments for security reasons. So you have to check this before you can using it.

koyaanisqatsi
  • 2,585
  • 2
  • 8
  • 15