This API provides shell related functionality, such as the current working directory, program search path and aliases for the shell.
shell.getAlias(alias: string): string
nil
.shell.setAlias(alias: string, value: string or nil)
nil
as the value to remove an alias. Note that aliases are not limited to program names, you can include parameters as well. For example, view
is a default alias for edit -r
.shell.aliases(): function
shell.getWorkingDirectory(): string
os.getenv("PWD")
.shell.setWorkingDirectory(dir: string)
os.setenv("PWD", dir)
.shell.getPath(): string
shell.resolve
. This can contain multiple paths, separated by colons (:
).os.getenv("PATH")
.shell.setPath(value: string)
shell.setPath(shell.getPath() .. ":/some/path")
os.setenv("PATH", value)
.shell.resolve(path: string[, ext: string]): string
path
would only contain the name. This first searches the working directory, then all entries in the search path (see getPath
/setPath
).path .. "." .. ext
.shell.execute(command: string, env: table[, ...]): boolean ...
os.getenv("SHELL")
) and passes the command to it. env
is the environment table to use for the shell, and thus for the called program, in case you wish to sandbox it or avoid it cluttering the caller's namespace. Additional arguments are passed directly to the first program started based on the command, so you can pass non-string values to programs.pcall
and coroutine.resume
: the first returned value is a boolean indicating success or error. In case of errors, the second returned value is a detailed error message. Otherwise the remaining returned values are the values that were returned by the specified program when it terminated.shell.parse(...): table, table
-
, and all options must only be a single character, since multiple characters following a single -
will be interpreted as multiple options. Options specified with 2 dashes are not split and can have multiple letters. Also, 2-dash options can be given values by using an equal sign. The following examples all assume the script program
parses the options using local args, ops = shell.parse(...)
.
program
# args
is {}
# ops
is {}
.
program -abC -d arg1 arg2
# args
is {"arg1", "arg2"}
# ops
is {a=true,b=true,C=true,d=true}
.
program -abC --dog arg1 arg2
# args
is {"arg1", "arg2"}
# ops
is {a=true,b=true,C=true,dog=true}
.
program -abC --dog=foo arg1 arg2
# args
is {"arg1", "arg2"}
# ops
is {a=true,b=true,C=true,dog="foo"}
.
On this next example, notice the single dash before dog
, this causes all of the token to be parsed as single chars.
program -abC -dog=foo arg1 arg2
# args
is {"arg1", "arg2"}
# ops
is {a=true,b=true,C=true,d=true,g=true,["="]=true,f=true,o=true}
.