Shell emulation
Constants
Version
sh.VERSION
Module version (currently 0.2)
Current Directory
sh.pwd()
Change directory:
sh.cd('nextdir')
Difference from unix-like systems: the root directory is the empty one (''), not the '/'. When changing directories, do not put the '/' prefix. I.e to change from the root directory to mydir, call sh.cd('mydir').
Remove a file or a directory
sh.rm(file, force=False)
file- name of a file within the current directory (sh.pwd())force- force recursive removal iffileis a directory (be careful!)
Move a file
sh.mv(src, target)
src- name of a file within the current directory (sh.pwd())target- new file name
Copy a file
sh.cp(src, target)
src- name of a file within the current directory (sh.pwd())target- destination file name.
List directory contents
sh.ls(src='', attr=False, ext=None)
src- the name of a subdirectory of the current directory. Leave empty to list the contents of the current directoryattr- if true, print extended information about each item listedext- optional filter for file extensions. Pass extension only, without preceding dot
Make directory
sh.mkdir(name)
Create a new directory named name inside the current directory
Print the contents of a file
sh.cat(name, lines=0)
name- file namelines- if non-zero: prepend each line printed with its number, starting fromlines(usually you'd want to pass 1 here)
Write to file
sh.echo(name, data, append=False)
(since version 0.2)
Write data to a file name. If append is true, the data is appended to the existing file data. If not, any existing data is silently overwritten.
Search in file
sh.grep(name, line=0, regex=None)
name- file nameline- if non-zero, print the corresponding line in file (line count stats from 1)regex- ifline==0, print lines containing the specified regular expression
If line==0 and regex is None, prints the whole file
Edit a file
sh.ed(name)
Open a Vim-like editor
Print text data to file
sh.type2file(filename)
Opens filename for writing and writes all the data, coming from the USB VCP to this file until a \x03 character (Ctrl+C) is found in the stream.