Difference between revisions of "Shell (API)"

From ComputerCraft Wiki
Jump to: navigation, search
m (Removed NeedsWork tag)
m (clarify shell.run parameters.)
Line 42: Line 42:
 
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Returns a {{type|table}} of programs.</td></tr>
 
<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}} program, {{type|string}} arguments)</td>
+
<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>
 
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Runs a program.</td></tr>
  
Line 48: Line 48:
 
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Returns the absolute path to the currently-executing program.</td></tr>
 
<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}} program, {{type|string}} arguments)</td>
+
<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>
 
<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>
  
Line 55: Line 55:
 
</table>
 
</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 22:54, 2 April 2014

The shell API allows you to interface with the shell.

Grid disk.png   Shell (API)

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

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.