Extra 's in luarocks issued path
I installed luarocks version 2.4.0 and I use it with lua version 5.2 on a ubuntu linux 16.04 machine.
When I enter
$luarocks path
I get as a result
export LUA_PATH='/home/myname/.luarocks/share/lua/5.2/?.lua;/home/myname/.luarocks/share/lua/5.2/?/init.lua;/usr/local/share/lua/5.2/?.lua;/usr/local/share/lua/5.2/?/init.lua;'/usr/local/share/lua/5.2/?.lua;'/home/myname/.luarocks/share/lua/5.2/?.lua;/usr/local/lib/lua/5.2/?.lua;/usr/local/lib/lua/5.2/?/init.lua;/usr/share/lua/5.2/?.lua;/usr/share/lua/5.2/?/init.lua;./?.lua'';/home/myname/.luarocks/share/lua/5.2/?.lua''
Note file inserted 's in the middle of the string, so the entry for the path of the current directory evaluates like that:
./?.lua'';
This path is not evaluated correctly, .lua-files in the local directory can not be required.
Am I doing something wrong here?
Best regards, majo83
At first glance, I can't reproduce it in my system... what are the existing values of your LUA_CPATH and LUA_PATH variables in your shell?
I see this as well, luarocks 2.2.2 on fedora 22, with lua 5.1
$ echo $LUA_PATH
$ echo $LUA_CPATH
$ luarocks51 path
export LUA_PATH='/home/karlp/.luarocks/share/lua/5.1/?.lua;/home/karlp/.luarocks/share/lua/5.1/?/init.lua;/home/karlp/.luarocks51/share/lua/5.1/?.lua;/home/karlp/.luarocks51/share/lua/5.1/?/init.lua;./?.lua;/usr/share/lua/5.1/?.lua;/usr/share/lua/5.1/?/init.lua;/usr/lib64/lua/5.1/?.lua;/usr/lib64/lua/5.1/?/init.lua'
export LUA_CPATH='/home/karlp/.luarocks/lib/lua/5.1/?.so;/home/karlp/.luarocks51/lib/lua/5.1/?.so;./?.so;/usr/lib64/lua/5.1/?.so;/usr/lib64/lua/5.1/loadall.so'
karlp@cuth:~/src/cbms3/smartfw32/em2 (em-range-scripts *)$ lua-5.1
Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio
> print(package.path)
./?.lua;/usr/share/lua/5.1/?.lua;/usr/share/lua/5.1/?/init.lua;/usr/lib64/lua/5.1/?.lua;/usr/lib64/lua/5.1/?/init.lua
>
$ lua-5.1 -lblahdsfads
lua-5.1: module 'blahdsfads' not found:
no field package.preload['blahdsfads']
no file './blahdsfads.lua'
no file '/usr/share/lua/5.1/blahdsfads.lua'
no file '/usr/share/lua/5.1/blahdsfads/init.lua'
no file '/usr/lib64/lua/5.1/blahdsfads.lua'
no file '/usr/lib64/lua/5.1/blahdsfads/init.lua'
no file './blahdsfads.so'
no file '/usr/lib64/lua/5.1/blahdsfads.so'
no file '/usr/lib64/lua/5.1/loadall.so'
stack traceback:
[C]: ?
[C]: ?
you need to
eval `luarocks path`
instead of
`luarocks path`
eval will get rid of the extra single quotes, and I sunk too much time into this figuring that out, to actually care why at this point, maybe some bash guru knows, but not me.
Anyway, the manual does include the eval part, so the fault is solely on my side :(
Thanks for catching the issue, @E14!
That's a hack. it's still wrong to be inserting the ' marks in garbage places like that. If it's going to generate a path, it should generate a path, not something that can be massaged later into something that works as a path.
And where is this manual that includes the eval?
man bash
luarocks help path says something like
On Unix systems, you may run: eval `luarocks path` And on Windows: luarocks path > "%temp%\_lrp.bat" && call "%temp%\_lrp.bat" && del "%temp%\_lrp.bat"
and the Wiki page on luarocks path mentions something similar.
@ildar really? helpful much? So whenever you have the following text.
export MYVAR=something
You never actually just execute that, you wrap everything in eval? lies. man bash yourself.
@karlp , I am sorry. I was just answering your question:
And where is this manual that includes the eval?
The correct answer is man bash . No reason to be rude, I didn't "RTFM"
you.
You never actually just execute that, you wrap everything in eval? lies. man bash yourself.
luarocks path is documented to:
Returns the package path currently configured for this installation of LuaRocks, formatted as shell commands to update LUA_PATH and LUA_CPATH.
The shell commands are not run: that's up to you to do yourself. You may want to append them to some script; or run them in the current session. The most common case (using for current session) is given as an example in luarocks documentation. Which is as @siffiejoe quoted above.
Yes, they're formatted as shell commands. Except they are formatted as illegal shell commands, and running "eval" on the returned shell commands works around this. luarocks is path wrongly generating quotes. The fact that the documentation says to "eval" the returned text is documenting a workaround.
@karlp they're not illegal... I'd run them through bash --posix while trying to figure this out. They work perfectly.
I'm quite certain that the issue is that the return of a command substitution is handled differently, eg.
the command 'ls' is the same as just ls when directly entered in the shell, but $(echo \'ls\') causes the error -bash: 'ls': command not found.
However, the command substitution is not part of the shell code returned by luarocks path and the peculiarities of how command substitution works can hardly be the fault of luarocks.
So we could argue that the guide should point this out specifically since it's an edge case not often encountered and easily overlooked by "normal power users" (like my humble self), but that's about it from my PoV.
@karlp no, that's not documenting a workaround, it's the right way of dealing with the shell.
luarocks path prints out the commands as they should be executed, using proper quotes to handle paths with spaces portably. Running $(luarocks path) by itself, the special characters (quotes, ?, etc.) are automatically escaped by the shell. The way to un-escape these and run them in the current shell is to use eval. The extra quotes you get are the result of dumping the auto-escaped variants straight into your environment.
No. this bug was filed because it doesn't print out properly quoted paths.
This bug was filed because $(luarocks path) doesn't always work, because it generated incorrectly quoted paths. My example quoted above is valid but I was also seeing it generate with quotes in the middle of the variable, as in the original filer report. My report above is bogus, and I'm sorry for that, but was I getting this on different computers, and it's because of the invalid quoting.
@karlp If you run $(luarocks path) (without eval) in an environment once, subsequent luarocks path calls (whether or not they're changing environment variables) will generate extra ', since luarocks path combines its values with the current environment, but the variable itself will contain 's if you skipped the eval.
What @E14 said. You got bad results because the variable had bad contents due to an earlier incorrect use.
So, if I understand what you guys are really trying to say, it's that you consider the following behaviour to be by design rather than a bug. If that's the case, then clearly there's no help. Note that the help for luarocks path says:
Returns the package path currently configured for this installation
of LuaRocks, formatted as shell commands to update LUA_PATH and LUA_CPATH.
karlp@cuth:~$ echo $LUA_CPATH
karlp@cuth:~$ $(luarocks53 path)
karlp@cuth:~$ echo $LUA_CPATH
'/home/karlp/.luarocks/lib/lua/5.3/?.so;/home/karlp/.luarocks53/lib/lua/5.3/?.so;/usr/lib64/lua/5.3/?.so;/usr/lib64/lua/5.3/loadall.so;./?.so'
karlp@cuth:~$ $(luarocks53 path)
karlp@cuth:~$ echo $LUA_CPATH
'/home/karlp/.luarocks/lib/lua/5.3/?.so;/home/karlp/.luarocks53/lib/lua/5.3/?.so;'/home/karlp/.luarocks/lib/lua/5.3/?.so;/usr/lib64/lua/5.3/?.so;/usr/lib64/lua/5.3/loadall.so;./?.so''
karlp@cuth:~$ $(luarocks53 path)
karlp@cuth:~$ echo $LUA_CPATH
'/home/karlp/.luarocks/lib/lua/5.3/?.so;/home/karlp/.luarocks53/lib/lua/5.3/?.so;'/home/karlp/.luarocks/lib/lua/5.3/?.so;/usr/lib64/lua/5.3/?.so;/usr/lib64/lua/5.3/loadall.so;./?.so'''
karlp@cuth:~$ luarocks53 path
export LUA_PATH='/home/karlp/.luarocks/share/lua/5.3/?.lua;/home/karlp/.luarocks/share/lua/5.3/?/init.lua;/home/karlp/.luarocks53/share/lua/5.3/?.lua;/home/karlp/.luarocks53/share/lua/5.3/?/init.lua;'/home/karlp/.luarocks/share/lua/5.3/?.lua;/usr/share/lua/5.3/?.lua;/usr/share/lua/5.3/?/init.lua;/usr/lib64/lua/5.3/?.lua;/usr/lib64/lua/5.3/?/init.lua;./?.lua;./?/init.lua''''
export LUA_CPATH='/home/karlp/.luarocks/lib/lua/5.3/?.so;/home/karlp/.luarocks53/lib/lua/5.3/?.so;'/home/karlp/.luarocks/lib/lua/5.3/?.so;/usr/lib64/lua/5.3/?.so;/usr/lib64/lua/5.3/loadall.so;./?.so''''
karlp@cuth:~$
I don't know if I get where you're going, do you mean the output should be an error if the path is invalid?
Shouldn't the output of luarocks path be the same for repeated invocations? It should just return the package path for the luarocks installation?