Difference between revisions of "Shell (API)"

From ComputerCraft Wiki
Jump to: navigation, search
m (clarify shell.run parameters.)
(Wiki table.)
Line 1: Line 1:
 
The shell API allows you to interface with the [http://en.wikipedia.org/wiki/Shell_%28computing%29 shell].
 
The shell API allows you to interface with the [http://en.wikipedia.org/wiki/Shell_%28computing%29 shell].
  
<table style="width: 100%; border: solid 1px black; margin: 2px; border-spacing: 0px;">
+
==API==
<tr><td colspan="2" style="font-weight: bold; font-size: large; padding-bottom: .3em; border-bottom: solid #C9C9C9 1px; background: #D3FFC2; line-height:28px;">
+
{| class="wikitable"
[[File:Grid_disk.png|24px]]&nbsp;&nbsp;
+
! width="100px" | Returns
Shell (API)
+
! width="200px" | Method name
</td></tr>
+
! Description
 +
|-
 +
|
 +
|[[shell.exit]]()
 +
|Exits the current shell.
 +
|-
 +
|{{type|string}} directory
 +
|[[shell.dir]]()
 +
|Returns the directory.
 +
|-
 +
|
 +
|[[shell.setDir]]({{type|string}} path)
 +
|Sets the directory.
 +
|-
 +
|{{type|string}} path
 +
|[[shell.path]]()
 +
|Returns the path.
 +
|-
 +
|
 +
|[[shell.setPath]]({{type|string}} path)
 +
|Sets the path.
 +
|-
 +
|{{type|string}} path
 +
|[[shell.resolve]]({{type|string}} localpath)
 +
|Resolves a local path to an absolute path.
 +
|-
 +
|{{type|string}} path
 +
|[[shell.resolveProgram]]({{type|string}} name)
 +
|Resolves the absolute path to the program whose name you provided.
 +
|-
 +
|{{type|table}} aliases
 +
|[[shell.aliases]]()
 +
|Returns aliases.
 +
|-
 +
|
 +
|[[shell.setAlias]]({{type|string}} alias, {{type|string}} program)
 +
|Sets an alias.
 +
|-
 +
|
 +
|[[shell.clearAlias]]({{type|string}} alias)
 +
|Clears an alias.
 +
|-
 +
|{{type|table}} programs
 +
|[[shell.programs]]([<nowiki></nowiki>{{type|boolean}} hidden])
 +
|Returns a {{type|table}} of programs.
 +
|-
 +
|{{type|boolean}} success
 +
|[[shell.run]]({{type|string}} command [, {{type|string}} args1, {{type|string}} args2, ...])
 +
|Runs a program.
 +
|-
 +
|{{type|string}} path
 +
|[[shell.getRunningProgram]]()
 +
|Returns the absolute path to the currently-executing program.
 +
|-
 +
|{{type|number}} newTabID
 +
|[[shell.openTab]]({{type|string}} command [, {{type|string}} args1, {{type|string}} args2, ...])
 +
|Runs a program in another [[multishell]] tab. ''Requires version 1.6 or newer and an advanced system.''
 +
|-
 +
|
 +
|[[shell.switchTab]]({{type|number}} tabID)
 +
|Switches the [[multishell]] tab to tab with the given ID.  ''Requires version 1.6 or newer and an advanced system.''
 +
|}
  
<tr><td style="width: 350px; background: #E0E0E0; padding: .4em; font-weight:bold;">Method Name</td><td style="background: #E0E0E0; padding: .4em; font-weight:bold;">Description</td></tr>
+
Note that [[shell.run]] and [[shell.openTab]] concatenate any arguments they are given (with single space separator characters) before parsing the command, and as of ComputerCraft version ''???'', now also support a single string containing ''all'' parameters.
 
+
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[shell.exit]]()</td>
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Exits the current shell</td></tr>
+
 
+
<tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[shell.dir]]()</td>
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Returns the directory</td></tr>
+
 
+
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[shell.setDir]]({{type|string}} path)</td>
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Sets the directory</td></tr>
+
 
+
<tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[shell.path]]()</td>
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Returns the path</td></tr>
+
 
+
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[shell.setPath]]({{type|string}} path)</td>
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Sets the path</td></tr>
+
 
+
<tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[shell.resolve]]({{type|string}} localpath)</td>
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Resolves a local path to an absolute path.</td></tr>
+
 
+
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[shell.resolveProgram]]({{type|string}} name)</td>
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Resolves the absolute path to the program whose name you provided.</td></tr>
+
 
+
<tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[shell.aliases]]()</td>
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Returns aliases.</td></tr>
+
 
+
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[shell.setAlias]]({{type|string}} alias, {{type|string}} program)</td>
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Sets an alias.</td></tr>
+
 
+
<tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[shell.clearAlias]]({{type|string}} alias)</td>
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Clears an alias.</td></tr>
+
 
+
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[shell.programs]]([<nowiki></nowiki>{{type|boolean}} hidden])</td>
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Returns a {{type|table}} of programs.</td></tr>
+
 
+
<tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[shell.run]]({{type|string}} command)</td>
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Runs a program.</td></tr>
+
 
+
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[shell.getRunningProgram]]()</td>
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Returns the absolute path to the currently-executing program.</td></tr>
+
 
+
<tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[shell.openTab]]({{type|string}} command)</td>
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Runs a program in another [[multishell]] tab. ''Requires version 1.6 or newer and an advanced computer.''</td></tr>
+
 
+
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[shell.switchTab]]({{type|number}} tab ID)</td>
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Switches the [[multishell]] tab to tab with the given ID.  ''Requires version 1.6 or newer and an advanced computer.''</td></tr>
+
</table>
+
 
+
Note that [[shell.run]] and [[shell.openTab]] concatenate any arguments they are given with single space separator characters before parsing the command.  This is backwards compatible with scripts written when shell.run required one string argument for the program, and one per argument for that program, but accepts a single string with the entire command as well.
+
  
 
[[Category:APIs]]
 
[[Category:APIs]]

Revision as of 07:30, 4 April 2014

The shell API allows you to interface with the shell.

API

Returns Method name Description
shell.exit() Exits the current shell.
string directory shell.dir() Returns the directory.
shell.setDir(string path) Sets the directory.
string path shell.path() Returns the path.
shell.setPath(string path) Sets the path.
string path shell.resolve(string localpath) Resolves a local path to an absolute path.
string path shell.resolveProgram(string name) Resolves the absolute path to the program whose name you provided.
table aliases shell.aliases() Returns aliases.
shell.setAlias(string alias, string program) Sets an alias.
shell.clearAlias(string alias) Clears an alias.
table programs shell.programs([boolean hidden]) Returns a table of programs.
boolean success shell.run(string command [, string args1, string args2, ...]) Runs a program.
string path shell.getRunningProgram() Returns the absolute path to the currently-executing program.
number newTabID shell.openTab(string command [, string args1, string args2, ...]) Runs a program in another multishell tab. Requires version 1.6 or newer and an advanced system.
shell.switchTab(number tabID) Switches the multishell tab to tab with the given ID. Requires version 1.6 or newer and an advanced system.

Note that shell.run and shell.openTab concatenate any arguments they are given (with single space separator characters) before parsing the command, and as of ComputerCraft version ???, now also support a single string containing all parameters.