Closed Layerex closed 2 years ago
io.popen
itself invokes/bin/sh -c arg
, so no shell invocation is required.
It seems to invoke user's login shell, whatever it is, not sh
. On my machine it invokes zsh
, at least. On other machine it could be something like fish
, which is not POSIX-compliant at all, I thought.
> io.popen('echo $SHELL'):read()
/bin/zsh
Yes, it launches fish
, if I change shell to fish
.
It seems to invoke user's login shell, whatever it is, not sh.
popen
C function is required by POSIX to shell out to a POSIX sh-compatible shell. Lua’s os.popen
simply calls the C function./bin/sh
.popen
shells out to /bin/sh
: This command is passed to /bin/sh using the -c flag; interpretation, if any, is performed by the shell.
/bin/sh
is a symlink to some other shell, be it bash, zsh, fish, or something else. But the convention is that the shell should read its argv[0]
(“by which name was I invoked?”), and, if it is sh
or /bin/sh
, enable POSIX sh-compatibility mode. Any [Linux] system that has /bin/sh
symlinked to something that does not do that would be pretty much broken. bash explicitly documents this in its manpage: When invoked as sh, bash enters posix mode after the startup files are read.
OK, so this will be merged after echo "$dir"/temp*_input
is changed to printf '%s\n' "$dir"/temp*_input
(in both widgets): it is possible that the glob here expands to multiple files, but the Lua code expects filenames separated by newlines.
io.popen
itself invokes/bin/sh -c arg
, so no shell invocation is required.shopt -s nullglob
and$(<file)
are bashisms, butpopen
is only required to invoke POSIX-compatible shell. Rewrite to the following: