此API提供了与shell相关的功能,例如shell的当前工作目录、程序查找路径和别名。
shell.getAlias(alias: string): stringnil。shell.setAlias(alias: string, value: string or nil)nil作为参数即可移除一条别名。请注意别名不仅限于程序名,也可以包含参数。例如,默认情况下view就是edit -r的别名。shell.aliases(): functionshell.getWorkingDirectory(): stringos.getenv("PWD")的别名。shell.setWorkingDirectory(dir: string)os.setenv("PWD", dir)的经校验版本。shell.getPath(): stringshell.resolve使用的搜索路径。此结果可能包含多条路径,中间用冒号(:)隔开。os.getenv("PATH") 的别名。shell.setPath(value: string)shell.setPath(shell.getPath() .. ":/some/path")os.setenv("PATH", value)的别名。shell.resolve(path: string[, ext: string]): stringpath中只应当包含文件名(不含后缀)。getPath/setPath )。path .. "." .. ext。shell.execute(command: string, env: table[, ...]): boolean ...os.getenv("SHELL"))并将命令作为参数传递给它。env是提供给shell使用的环境表,以备你希望在沙盒环境中运行程序,或者防止程序污染调用者的命名空间。额外参数会被直接传递给基于给定命令启动的第一个程序,因此你可以向程序传递非字符串值。pcall和coroutine.resume:第一个返回值为布尔值,代表了执行是否成功。当发生错误时,第二个返回值为详细报错信息。其他情况下,第一条之后的返回值均为指定程序结束后返回的结果。shell.parse(...): table, table-进行标记,所有的选项都只能为单个字母长,因为一个-后面跟着多个字母会被认为是多个选项。以两个破折号开头的选项不会被拆分,也就可以有多个字符长。并且,双破折号的选项还可以使用等于号赋值。下列样例均假定脚本program使用local args, ops = shell.parse(...)解析选项。programargs为{}ops为{}program -abC -d arg1 arg2args为{"arg1", "arg2"}ops为{a=true,b=true,C=true,d=true}program -abC --dog arg1 arg2args为{"arg1", "arg2"}ops为{a=true,b=true,C=true,dog=true}program -abC --dog=foo arg1 arg2args为{"arg1", "arg2"}ops为{a=true,b=true,C=true,dog="foo"}dog 前面的单破折号。这使得后续所有字符均被解析为单独字符。program -abC -dog=foo arg1 arg2args为{"arg1", "arg2"}ops为{a=true,b=true,C=true,d=true,g=true,["="]=true,f=true,o=true}