Difference between revisions of "Shell (API)"
From ComputerCraft Wiki
MKlegoman357 (Talk | contribs) m (Rewrote some descriptions of some functions) |
MKlegoman357 (Talk | contribs) m (Recreated table using {{API table}} tags) |
||
Line 1: | Line 1: | ||
− | The shell API allows you to interface with the [http://en.wikipedia.org/wiki/Shell_%28computing%29 shell]. | + | {{lowercase}} |
+ | The shell API allows you to interface with the [http://en.wikipedia.org/wiki/Shell_%28computing%29 shell]. The shell API is only available when programs are ran from the shell or using [[shell.run]]/[[shell.openTab]]. | ||
==API== | ==API== | ||
− | {| | + | |
− | + | {{API table|shell|image=Grid disk.png|2= | |
− | + | ||
− | + | {{API table/row | |
− | + | ||
− | + | ||
|[[shell.exit]]() | |[[shell.exit]]() | ||
+ | |{{type|nil}} | ||
|Exits the current shell. | |Exits the current shell. | ||
− | | | + | |odd}} |
− | + | ||
+ | {{API table/row | ||
|[[shell.dir]]() | |[[shell.dir]]() | ||
− | |Returns the path to the working directory. | + | |{{type|string}} directory |
− | + | |Returns the path to the working directory.}} | |
− | + | ||
+ | {{API table/row | ||
|[[shell.setDir]]({{type|string}} path) | |[[shell.setDir]]({{type|string}} path) | ||
+ | |{{type|nil}} | ||
|Sets the working directory. | |Sets the working directory. | ||
− | | | + | |odd}} |
− | + | ||
+ | {{API table/row | ||
|[[shell.path]]() | |[[shell.path]]() | ||
− | |Returns the path. | + | |{{type|string}} path |
− | + | |Returns the path.}} | |
− | + | ||
+ | {{API table/row | ||
|[[shell.setPath]]({{type|string}} path) | |[[shell.setPath]]({{type|string}} path) | ||
+ | |{{type|nil}} | ||
|Sets the path. | |Sets the path. | ||
− | | | + | |odd}} |
− | + | ||
− | |[[shell.resolve]]({{type|string}} | + | {{API table/row |
− | |Resolves a local path to an absolute path. | + | |[[shell.resolve]]({{type|string}} localPath) |
− | + | |{{type|string}} absolutePath | |
− | + | |Resolves a local path to an absolute path.}} | |
+ | |||
+ | {{API table/row | ||
|[[shell.resolveProgram]]({{type|string}} name) | |[[shell.resolveProgram]]({{type|string}} name) | ||
+ | |{{type|string}} absolutePath | ||
|Resolves the absolute path to the program whose name you provided. | |Resolves the absolute path to the program whose name you provided. | ||
− | | | + | |odd}} |
− | + | ||
+ | {{API table/row | ||
|[[shell.aliases]]() | |[[shell.aliases]]() | ||
− | |Returns aliases. | + | |{{type|table}} aliases |
− | + | |Returns aliases.}} | |
− | + | ||
+ | {{API table/row | ||
|[[shell.setAlias]]({{type|string}} alias, {{type|string}} program) | |[[shell.setAlias]]({{type|string}} alias, {{type|string}} program) | ||
− | |Sets an alias. | + | |{{type|nil}} |
− | | | + | |Sets an alias for ''program''. |
− | + | |odd}} | |
+ | |||
+ | {{API table/row | ||
|[[shell.clearAlias]]({{type|string}} alias) | |[[shell.clearAlias]]({{type|string}} alias) | ||
− | |Clears an alias. | + | |{{type|nil}} |
− | + | |Clears an alias.}} | |
− | + | ||
+ | {{API table/row | ||
|[[shell.programs]]([<nowiki/>{{type|boolean}} showHidden]) | |[[shell.programs]]([<nowiki/>{{type|boolean}} showHidden]) | ||
− | |Returns a table of files in the current directory and in | + | |{{type|table}} programs |
− | + | |Returns a table of files in the current directory and in all paths in [[shell.path]]. | |
− | + | |odd}} | |
− | + | ||
− | + | ||
− | + | {{API table/row | |
− | + | ||
|[[shell.getRunningProgram]]() | |[[shell.getRunningProgram]]() | ||
− | |Returns the absolute path to the currently-executing program. | + | |{{type|string}} path |
− | | | + | |Returns the absolute path to the currently-executing program.}} |
− | |{{type| | + | |
+ | {{API table/row | ||
+ | |[[shell.run]]({{type|string}} command [, {{type|string}} args1, {{type|string}} args2, ...]) | ||
+ | |{{type|boolean}} success | ||
+ | |Runs a command (program). | ||
+ | |odd}} | ||
+ | |||
+ | {{API table/row | ||
|[[shell.openTab]]({{type|string}} command [, {{type|string}} args1, {{type|string}} args2, ...]) | |[[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.'' | + | |{{type|number}} tabID |
− | + | |Runs a program in another [[multishell]] tab. ''Requires version 1.6 or newer and an advanced system.''}} | |
− | + | ||
+ | {{API table/row | ||
|[[shell.switchTab]]({{type|number}} tabID) | |[[shell.switchTab]]({{type|number}} tabID) | ||
+ | |{{type|nil}} | ||
|Switches the [[multishell]] tab to tab with the given ID. ''Requires version 1.6 or newer and an advanced system.'' | |Switches the [[multishell]] tab to tab with the given ID. ''Requires version 1.6 or newer and an advanced system.'' | ||
− | |} | + | |odd}} |
+ | |||
+ | }} | ||
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 1.45, now also support a single string containing ''all'' parameters. | 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 1.45, now also support a single string containing ''all'' parameters. | ||
[[Category:APIs]] | [[Category:APIs]] |
Revision as of 19:00, 8 April 2014
The shell API allows you to interface with the shell. The shell API is only available when programs are ran from the shell or using shell.run/shell.openTab.
API
shell (API) | ||
---|---|---|
Function | Return values | Description |
shell.exit() | nil | Exits the current shell. |
shell.dir() | string directory | Returns the path to the working directory. |
shell.setDir(string path) | nil | Sets the working directory. |
shell.path() | string path | Returns the path. |
shell.setPath(string path) | nil | Sets the path. |
shell.resolve(string localPath) | string absolutePath | Resolves a local path to an absolute path. |
shell.resolveProgram(string name) | string absolutePath | Resolves the absolute path to the program whose name you provided. |
shell.aliases() | table aliases | Returns aliases. |
shell.setAlias(string alias, string program) | nil | Sets an alias for program. |
shell.clearAlias(string alias) | nil | Clears an alias. |
shell.programs([boolean showHidden]) | table programs | Returns a table of files in the current directory and in all paths in shell.path. |
shell.getRunningProgram() | string path | Returns the absolute path to the currently-executing program. |
shell.run(string command [, string args1, string args2, ...]) | boolean success | Runs a command (program). |
shell.openTab(string command [, string args1, string args2, ...]) | number tabID | Runs a program in another multishell tab. Requires version 1.6 or newer and an advanced system. |
shell.switchTab(number tabID) | nil | 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 1.45, now also support a single string containing all parameters.