User Tools

Site Tools


mmbasic:mmunix_unix_like_commands_cat_dir_grep_more

MMUNIX - UNIX-like commands: cat dir grep more

UNIX-like Commands for the MaxiMite

The following four UNIX-like commands are implemented as “implied RUN commands” (see page 24 of the MMBasic manual for implied RUN commands):

cat   catenate files to output
dir   list files
grep  search files using a pattern or string
more  file pager and hexdump

These commands support the following useful command-line features:

  • File and directory name globbing with * and ?
  • Paths can be separated with \ as usual or with /
  • Input can be redirected with < FILE
  • Output can be redirected with > FILE or » FILE (append)

These are implied RUN commands that you can rename, for example rename file CAT.BAS to MMCAT.BAS to rename cat to mmcat.

Download

Download MMUNIX.zip from Attachments in the upper right corner.

cat - CAT.BAS

Catenates one or more files to output.

Usage:

cat PATHNAMES
< FILE    redirect input from the specified FILE
> FILE    redirect output to the specified FILE
>> FILE   append output to the specified FILE
PATHNAMES list of dir/file paths to catenate, using * and ? wildcards

When PATHNAMES is not provided or a - argument is provided then this command reads input from standard input.

Example:

Catenate all .bas files in the project directory into bundle.bas:
cat project/*.bas > bundle.bas

dir - DIR.BAS

Lists the contents of one or more directories.

Usage:

dir [-a][-p] PATHNAMES
-a        show hidden files and directories
-p        do not pause
< FILE    redirect input from the specified FILE
> FILE    redirect output to the specified FILE
>> FILE   append output to the specified FILE
PATHNAMES list of dir/file paths to list, using * and ? wildcards

When PATHNAMES is not provided, lists the contenst of the current directory.

Example:

List the contents of the project and reports directories without pausing:
dir -p project reports

grep - GREP.BAS

Searches one or more files for a regex pattern or string match.

Usage:

grep [-f][-n] "PATTERN" PATHNAMES
-f        fast string matching
-n        include line numbers in the output
< FILE    redirect input from the specified FILE
> FILE    redirect output to the specified FILE
>> FILE   append output to the specified FILE
PATTERN   regex composed of . &#0091;]] ? * + ^ $
PATHNAMES list of dir/file paths to search, using * and ? wildcards

Option -f matches a string provided as “PATTERN”, rather than a regex, and is much faster.

Regex syntax:

.     matches any character
[abc] matches a, b or c
\.    matches ., likewise <code>\?</code> matches ?, <code>\\</code> matches \ and so on
?     matches zero or one of the previous character, reluctantly
*     matches zero or more of the previous character, reluctantly
+     matches one or more of the previous character, reluctantly
^     matches begin of text
$     matches end of text

Example:

Search and display the lines with line numbers of .bas files in the project directory that have the text "Usage" at the start of the line: 
grep -n "^Usage:" project/*.bas

more - MORE.BAS

Page through one or more files or display hexdump.

The pager pauses after each page is displayed, use keys to advance:

SPACE next page
ENTER next line
ESC   quit this file

Usage:

more [-a][-n][-p][-r][-x] PATHNAMES
-a        show contents of hidden files
-n        add line numbers
-p        do not pause
-r        show raw control characters
-x        show hex dump
< FILE    redirect input from the specified FILE
> FILE    redirect output to the specified FILE
>> FILE   append output to the specified FILE
PATHNAMES list of dir/file paths to display, using * and ? wildcards

Option -x displays a hexdump and ASCII table of the file contents.

Example:

Display all .bas files in the project directory and its subdirectories:
more project/*.bas project/*/*.bas

BSD-3 open source, Copyright R.A. van Engelen

mmbasic/mmunix_unix_like_commands_cat_dir_grep_more.txt · Last modified: 2024/02/07 14:54 by gerry