Advanced shell

The advanced shell

The advanced shell is an extension to the simple shell. It adds some new features to the simple shell:

  • file masks

  • more file operations (rename and move)

  • recursive operations (for example recursive copies of directories)

A detailed description of the advanced shell commands and the structure of the file masks are given below.

File masks

Warning Read this section carefully, eLua's idea of file masks ia different from what you might have encountered in various operating systems.

The advanced shell supports file masks for various file operations (for example cp). A file mask can match zero, one or more files. In order to match more than one file, it uses two special characters:

  • ?: this matches exactly one character

  • *: this matches zero or more characters, non-greedy (it stops at the first non-special character). Any ? characters immediately following the * will be ignored.

This is probably best understood by some examples. Given the filenames below:

a
ab
abcd
abba
aaba
aaab
bbbcd
dccdb

this is how various file masks work:

  • * : all the files above

  • a* : a, ab, abcd, abba, aaba, aaab

  • a*b : ab, aaab

  • a*?b : ab, aaab

  • a*b? : aaba

  • *b* : ab, abcd, abba, aaba, aaab, bbbcd, dccdb

  • ???? : abcd, abba, aaba, aaab

  • a?*b : aaab

help

By itself, it shows a list of all shell commands. If a shell command is given after help, it displays detailed information about the given command. Examples:

# help
# help ls

ver

Print the version of the eLua image installed on the board. If the image is not an official one, an abbreviation of the git SHA1 revision used for building the image will be shown in the version number.

recv

Allows you to receive from the PC running the terminal emulator program, a Lua file (either source or compiled bytecode) via XMODEM and either execute it on your board or save it to a file. To use this feature, your eLua target image must be built with support for XMODEM (see building for details). Also, your terminal emulation program must support sending files via the XMODEM protocol. Both XMODEM with checksum and XMODEM with CRC are supported, but only XMODEM with 128 byte packets is allowed (XMODEM with 1K packets won’t work).

To start the transfer, enter recv at the shell prompt. eLua will respond with "Waiting for file …". At this point you can send the file to the eLua board via XMODEM. eLua will receive and execute the file. Don’t worry when you see C characters suddenly appearing on your terminal after you enter this command, this is how the XMODEM transfer is initiated. If you want to save the data to a file instead of executing it, use recv <filename> instead.

Since XMODEM is a protocol that uses serial lines, this command is not available if you’re running your console over TCP/IP instead of a serial link. If you’d like to send compiled bytecode to eLua instead of source code, please check this section first. Examples:

# recv
# recv /mmc/temp.lua

lua

This command allows you to start the Lua interpreter, optionally passing command line parameters, just as you would do from a desktop machine. There are some differences from the desktop Lua version in command line parsing:

  • the command line can’t be longer than 50 chars

  • character escaping is not implemented. For example, the next command won’t work because of the ' (simple quotes) escape sequences:

    eLua# lua -e 'print(\'Hello, World!\')' -i
    Press CTRL+Z to exit Lua
    lua: (command line):1: unexpected symbol near ''

    However, if you use both '' (simple quotes) and "" (double quotes) for string quoting, it will work:

    eLua# lua -e 'print("Hello, World")' -i
    Press CTRL+Z to exit Lua
    Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
    Hello, World
  • if you want to execute a file from the ROM file system (or from another file system), remember to prefix it with /rom. For example, to execute hello.lua, do this:

    eLua# lua /rom/hello.lua

ls or dir

Shows a list of all the files in the file systems used by eLua, as well as their size and the total size of the given file system. Syntax:

# ls [<path>] [-R]

If path is given, the listing is restricted to the file mask specified by path. If -R is given, ls will recurse through all the directories in path or through all the directories in all the available filesystems if path is not specified.

cat or type

Prints the content of (usually text) files on the console. Examples:

eLua# cat /rom/test.lua /mmc/temp.txt
eLua# cat /mmc/autorun.lua

cp

Copies a file or a directory. This command can be used to copy data between different file systems (for example between the MMC file system and the RFS file system). Syntax:

# cp <src> <dest> [-R] [-f] [-c] [-s]
  • <src> is the source file or directory. It can be a file mask.

  • <dest> is the destination. If it does not exist, it will be created. It can’t be a file mask.

  • -R: (optional) copy files and directories recursively.

  • -f: (optional) force file overwrite on <dest>. The default is to ask for confirmation before overriding.

  • -c: (optional) confirm each file copy operation.

  • -s: (optional) run the command normally, but don’t actually copy anything. Useful to check the outcome of the operation before actually executing it.

exit

Exits the shell. This only makes sense if eLua is compiled with terminal support over TCP/IP , as it closes the telnet session to the eLua board. Otherwise it just terminates the shell and blocks forever until you reset your board.

wofmt

"Formats" the WOFS file system, erasing its current contents. The user is asked to confirm this operation.

mkdir

Creates a new directory. The filesystem must have directory support in order fir this to work. Example:

# mkdir /mmc/dir

rm

Removes files and directories. Syntax:

# rm <filemask> [-R] [-c] [-s]
  • <filemask>: specify the file(s) or directories that are to be removed

  • -R: (optional) remove directories recursively. Use this flag to remove a directory with rm

  • -c: (optional) confirm each remove operation.

  • -s: (optional) run the command normally, but don’t actually remove anything. Useful to check the outcome of the operation before actually executing it.

mv

Moves a file or a directory. This command can be used to move data between different file systems (for example between the MMC file system and the RFS file system). Syntax:

# mv <src> <dest> [-R] [-f] [-c] [-s]
  • <src> is the source file or directory. It can be a file mask.

  • <dest> is the destination. If it does not exist, it will be created. It can’t be a file mask.

  • -R: (optional) move files and directories recursively.

  • -f: (optional) force file overwrite on <dest>. The default is to ask for confirmation before overriding.

  • -c: (optional) confirm each file move operation.

  • -s: (optional) run the command normally, but don’t actually move anything. Useful to check the outcome of the operation before actually executing it.