Skip to content

The shell

Jaume Olivé Petrus edited this page May 4, 2018 · 34 revisions

Lua RTOS has an integrated shell that allows you to execute certain commands in a linux similar way. The shell is disabled by default, but you can enable it typing os.shell(true) in the prompt or putting os.shell(true) in the system.lua file.

The following explains all the commands supported by the shell.

Utility commands

clear

Clear the terminal screen.

luac source [destination]

luac is the Lua compiler. It translates programs written in the Lua programming language (source argument) into binary files ([destination] argument) that can be later loaded and executed.

The main advantages of precompiling chunks are: faster loading, protecting source code from accidental user changes, and off-line syntax checking.

Precompiling does not imply faster execution because in Lua chunks are always compiled into bytecodes before being executed. luac simply allows those bytecodes to be saved in a file for later execution.

destination argument is optional, and if it's not provided the compiled filename is the source filename postfixed with the "c" character.

Example:

-- Compile test.lua into test.luac file
luac test.lua test.luac

-- Compile test.lua into test.luac file
luac test.lua

File system commands

cat file

Print the file on the standard output.

/ > cat system.lua
-- system.lua
--
-- This script is executed after a system boot or a system reset and is intended
-- for setup the system.

---------------------------------------------------
-- Main setups
---------------------------------------------------
os.loglevel(os.LOG_INFO)   -- Log level to info
os.logcons(true)           -- Enable/disable sys log messages to console
os.shell(true)             -- Enable/disable shell
os.history(false)          -- Enable/disable history
/ > 

cd directory

Change the working directory to directory.

/ > cd examples
/examples > 

cp source destination

Copy the source file to the destination file.

/ > cp autorun.lua autorun.old

ls pattern

Lists directory contents of files and directories that matches the pattern.

/ > ls *.lua
f	       0		autorun.lua
f	    2446		system.lua
f	    2445		config.lua
f	     252		test.lua
f	     280		test2.lua

mkdir directory

Creates a new directory named directory in the current directory.

more file

mv SOURCE DESTINATION

Move (rename) SOURCE to DESTINATION.

pwd

Print name of current/working directory.

/examples > pwd
/examples	
/examples > 

rm FILE

Remove FILE.

Network commands

System commands

dmesg

Print the syslog contents on the standard output.

Note: dmesg is only available if the underlying storage for your root filesystem is not the SPI FLASH.

reboot

Reboot the system.

Clone this wiki locally