Shell API

Functionshell.aliases
Returns a list of all aliases.
Syntax shell.aliases()
Returns table
Part of CC:Tweaked (source)
API shell
ExamplePrint all aliases
Print all aliases.
Code
<nowiki>
for alias,program in pairs(shell.aliases()) do
  print(alias..": "..program)
end
  </nowiki>
Output rm: delete

dir: list
clr: clear
sh: shell
ls: list
cp: copy
foreground: fg
background: bg
mv: move

rs: redstone
Functionshell.clearAlias
Clears an alias.
Syntax shell.clearAlias(
  • alias : string
)
Returns nil
Part of CC:Tweaked (source)
API shell
ExampleClears an Alias
Clears the alias "rm".
Code
<nowiki>
shell.clearAlias("rm")
  </nowiki>

Shell.complete Shell.completeProgram

Functionshell.dir
Returns the current shell working directory. Set by shell.setDir programmatically or the cd command from the shell itself. The working directory is displayed before the > of the shell prompt, and is used as the first component of relative paths by programs such as ls.
Syntax shell.dir()
Returns string path
Part of CC:Tweaked
API shell
ExamplePrint the current working directory.
Code
<nowiki>
print(shell.dir())
    </nowiki>
Output Path of the current working directory.
Functionshell.exit
Close the current shell.
Syntax shell.exit()
Returns nil
Part of CC:Tweaked (source)
API shell
ExampleClose the current shell.
Close the current shell.
Code
<nowiki>
shell.exit()
    </nowiki>

Shell.getCompletionInfo

Functionshell.getRunningProgram
Returns the running program executed by shell.run.
Syntax shell.getRunningProgram()
Returns string path
Part of CC:Tweaked
API shell
ExampleGet the path of a running program.
Returns the running program.
Code
<nowiki>
shell.getRunningProgram()
    </nowiki>
Output
Running program.
Functionshell.openTab
Run a program in a new multishell tab in the shell enviroment. This function only exits if multishell is enabled.
Syntax shell.openTab(
  • command : string
  • args...? : string
)
Returns number tabid
Part of CC:Tweaked (source)
API shell
ExampleRun a Program in a new tab.
Run "lua" in a new tab.
Code
<nowiki>
shell.openTab("lua")
    </nowiki>
Functionshell.path
Returns the Shellpath. The Shellpath is a list of folders, where the shell are searching for programs. The directories are separated with :.
Syntax shell.path()
Returns string
Part of CC:Tweaked (source)
API shell
ExampleGet the Shellpath
Print the Shellpath.
Code
<nowiki>
print(shell.path())
  </nowiki>
Output .:/rom/programs:/rom/programs/advanced:/rom/programs/rednet:/rom/programs/fun:/rom/programs/fun/advanced:/rom/programs/http
Functionshell.programs
Returns a list of all Programs in the Shellpath.
Syntax shell.programs()
Returns table
Part of CC:Tweaked (source)
API shell
ExampleGet a List of all Progarms in the Shellpath
Get a List of all Progarms in the Shellpath and print it.
Code
<nowiki>
for k,v in ipairs(shell.programs()) do
  write(v.." ")
end
  </nowiki>
Output adventure alias apis bg cd chat clear copy delete dj drive edit eject emu exit fg gps h hello help id label list lua mkdir monitor move multishell paint pastebin peripherals programs reboot redirection redstone rename repeat set shell shutdown time type wget worm

Shell.resolve Shell.resolveProgram

,

Functionshell.run
Runs a command in the computer's or turtle's shell.
Syntax shell.run(
  • command... : string
)
Returns boolean success
Part of CC:Tweaked
API shell
ExampleExecute a command in the shell
Opens the lua interface
Code
<nowiki>shell.run("lua")</nowiki>
Output
(Lua program is now running.)
ExampleExecute a splitted command in the shell
Lists all files/directories in /rom
Code
<nowiki>shell.run("list", "/rom")</nowiki>
Output
All files/directories in /rom
Functionshell.setAlias
Set an alias.
Syntax shell.setAlias(
  • alias : string
  • program : string
)
Returns nil
Part of CC:Tweaked (source)
API shell
ExampleSet an Alias
Set "rd" as alias for "redirection".
Code
<nowiki>
shell.setAlias("rd", "redirection")
  </nowiki>

Shell.setCompletionFunction

Functionshell.setDir
Sets the current shell directory. Throws a error, if the directory are not exists. You can get the current shell directory with shell.dir.
Syntax shell.setDir(
  • path : string
)
Returns nil
Part of CC:Tweaked (source)
API shell
ExampleSet the current shell directory.
Set the current shell directory to "/rom".
Code
shell.setDir("/rom")
Functionshell.setPath
Set the Shellpath. The Shellpath is a list of folders, where the shell are searching for programs. The directories are separated with :.
Syntax shell.setPath(
  • shellpath : string
)
Returns nil
Part of CC:Tweaked (source)
API shell
ExampleSet the Shellpath
Add "/programs" to the Shellpath.
Code
<nowiki>
shell.setPath(shell.path()..":/programs")
  </nowiki>
Functionshell.switchTab
Switch to another multishell tab. This function only exists if multishell is enabled.
Syntax shell.switchTab(
  • tabid : number
)
Returns nil
Part of CC:Tweaked (source)
API shell
ExampleSwitch the tab.
Switch to tab 1.
Code
<nowiki>
shell.switchTab(1)
    </nowiki>
This article is issued from Computercraft. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.