TweetFollow Us on Twitter

MPW Special Chars
Volume Number:6
Issue Number:7
Column Tag:MPW Notes

MPW Special Characters

By Mark Andrews, Mountain View, CA

Using Special Characters In the Command Language

[Mark Andrews is the author of 15 computer books, including Atari Roots, Programming the Commodore 64 in Assembly Language, and Programming the Apple IIGS in Assembly Language and C. His newest book is Inside MPW, to be published this fall by Addison-Wesley. This article is an excerpt from Inside MPW.]

There are two ways to go about designing a computer language. You can construct it like a spoken language, so that it will be easy to learn and understand. Or you can design it using a more concise but less English-like model, so it will be faster, more efficient--and, all too often, quite difficult to master.

When the creators of MPW sat down to develop a shell language, they could have made it a lot more user-friendly. For instance, they could have used the word TOP instead of the character • to represent the beginning of a file, the word BOTTOM instead of the symbol to represent the bottom, and the word SELECTION instead of § to represent the currently selected, or highlighted, text. That kind of approach would have made learning the MPW shell language a much less formidable task than it has turned out to be.

There would have been tradeoffs, of course. Once you’ve mastered the MPW command language, it’s much faster to type a command like •: than it is to type something like FROM TOP TO BOTTOM SELECT ALL, which would be a possible alternative in a more English-like language. And a command interpreter can certainly parse three ASCII characters much faster than it could handle a long sequence of words in a more user-friendly language.

But that’s really all quite academic. Like it or not, the MPW shell language is what we’ve got, and if you want to use MPW, there’s no alternative but to learn the MPW command language.

Actually, MPW language uses two sets of special characters. One set is made up of the punctuation marks and other special symbols that are printed on the Macintosh keyboard. The other set comes from the Macintosh extended character set: the set of characters that you get when you press a key on your keyboard while holding the Option key down. And those extended characters can be a real headache when you’re trying to master MPW. Not only do you have to learn how they’re used in the command language; since they don’t appear on the keyboard, you also have to figure out--and then memorize--where to find them.

To make matters even more difficult, many special characters have more than one meaning in MPW; when they appear in one context, they mean one thing, and when they’re used in a different context, they often mean another.

The most notorious character with two meanings is undoubtedly the symbol  (Option-D). When the  character appears alone at the end of a line, MPW runs that line and the next line together, creating a single line. But when  precedes the letter n, it acts as an escape character and generates a return.

Think about this for a moment, and you’ll realize that the character  has two meanings that are exact opposites. Sometimes it deletes a return, and sometimes it creates one!

There are many other special characters that have more than one meaning in MPW. For example, an exclamation point means “not” in string and arithmetic operations, but stands for a line of text in certain editing operations. The character § sometimes stands for the current selection (either a block of highlighted text or the current position of the cursor), and sometimes stands for the name of a file. And so on.

One way to sort out the ambiguities in the special characters used by MPW would be to to list every meaning of every special character used in the MPW command language, and then to examine and resolve each ambiguity that you find. And that’s just what has been done in Table 1 (except those used as arithmetic and logical operators/in menu commands/as number prefixes in arithmetic and logical operations), which appears at the end of this article. In addition to listing the meanings and categories of all special characters used in the MPW language, it shows how to type each character, describes the syntax in which each character is used, and provides an example showing how each character can be used in a command.

In compiling Table 1, I discovered that the MPW command language character set contains fourteen distinct kinds of characters. Since no breakdown of this kind had been published until I started working on Inside MPW, I took the liberty to draw up my own list of categories. From this research, these were the categories that emerged:

• Whitespace characters

• Command terminators

• Wildcard characters

• The escape character 

• The line-continuation character 

• The comment character #

• Delimiters

• The command substitution character ‘

• Filename generation operators

• Selection expressions

• Regular expression operators

• Redirection operators

• The number prefixes $, 0x, 0b, and 0 (not in Table 1)

• Arithmetical and logical operators (not in Table 1)

• Special characters used in makefiles

Whitespaces and Command Terminators

In MPW, a command is defined as a series of words and regular expressions separated by whitespaces and ending with a command terminator. There are only two whitespace characters in the MPW command language: Space and Tab. You can use either character to generate a space in an MPW command.

The most commonly used command terminator is the Return. Unless a return is followed immediately by the line continuation character , it always ends a command. Another command terminator that you’ll often see is the semicolon (;). By using a semicolon as a command terminator, you can type more than one command on a line.

The special-character combinations && and || are logical operators as well as command terminators. If you separate two commands with the characters &&, the second command will be executed only if the first command succeeds. Conversely, if you separate two commands with the characters ||, the second command will be executed only if the first command fails.

Selection Expressions

Selection expressions used in MPW include • (Option 8), which represents the beginning of a file; (Option-5), which represents the end of a file; and § (Option-6) which represents the current selection. Another selection expression is the character  (Option-J), which can be used to represent either the beginning or the end of a selection.

Delimiters

Many kinds of delimiters are used in the MPW command language. When you want to include a space or a special character in a string or an expression, you must enclose the command in single or double quotation marks.

If you use single quotes around an expression, every special character in the expression is interpreted literally, instead of being interpreted as a special character. If you use double quotes, all characters in the expression are taken literally except curly brackets ({...}), the backquote character (‘), and the escape character . If you want to use a shell variable as part of an expression, you must enclose the expression in single quotes, since variables in MPW are always delimited by curly brackets. And if the definition of a variable contains white spaces, then the curly brackets that enclose the variable must themselves be enclosed in quotes, like this: “{MPW}”.

If you want to use an apostrophe in a string, and don’t want it be be interpreted as a single quote, you can put double quotes around the word containing the apostrophe. Or you can precede the apostrophe with the escape character .

The slash bar (/) and the backslash (\) are often used as delimiters with the commands, Find, Search, and Replace. When a string or expression delimited by slash bars (/.../) follows a Find command, Find searches in a forward direction. But when Find is followed by a string or expression enclosed in backslashes (\...\), the search goes in a backwards direction. Hence, to start at the beginning of a file and search for the beginning of the string “charlie,” you could execute the commands

Find • ; Find /charlie/

But if you wanted to start at the end of a file and search backwards for end of the string “charlie,” you could execute the commands

Find   ; Find \charlie\

One very interesting delimiter is the backquote character (‘). By placing a command between a pair backquote characters, you can pass its output to another command. For example, when you execute the command

Echo ‘Files -t TEXT‘

the Files command compiles a list of files of the type TEXT, and passes the list to the Echo command, which then prints the list on the screen.

If there were enough space in this magazine, I could examine every special character used in MPW, and present interesting examples for each one--and, in Inside MPW, that’s exactly what is done. Meanwhile, until the book comes out, take some time to study the examples in Table 1. Unless you’re already an MPW wizard, chances are they can tell you a lot about how to use special characters in MPW.

AppleLink: D3001

TABLE 1: Special Characters Used in MPW

Chr Press Category UsageMeaningExampleTranslation
##Comment#sCharacters between# A commentString following # is interpreted as a comment
# and terminator
are interpreted
as a comment
""Delimiter"s"Delimits a stringEcho "{MPW}" >>Echo the contents of the shell variable {MPW}
in which each "{Target}"to the target window
character is taken
literally, except
for , {}, and ‘
''Delimiter's'Delimits a stringEcho '{MPW}' >>Echo the string "{MPW}" to the target window
in which all "{Target}"
characters are
taken literally
((Delimiter(p)Delimits a groupFind /("*")+/Select a group of one or more asterisks
of characters that
form a pattern
))Delimiter(p)Delimits a groupFind /("*")+/Select a group of one or more asterisks
of characters that
form a pattern
//Delimiter/r/Searches forwardFind /delta/Search forward and select the word "delta"
and selects regular
expression
»Option-Shift-\
Delimiter«n»Delimits numberFind /[t]«2»/Select exactly two tabs
standing for number
of repetitions
»Option-Shift-\
Delimiter«n,»Delimits numberFind /[t]«2,»/Select two or more tabs
standing for at
least n repetitions
»Option-Shift-\
Delimiter«n1,n2»Delimits numberFind /[t]«2,4»/Select two to four tabs
standing for n to
n repetitions
«Option-\
Delimiter«n»Delimits numberFind /[t]«2»/Select exactly two tabs
standing for number
of repetitions
«Option-\
Delimiter«n,»Delimits numberFind /[t]«2,»/Select two or more tabs
standing for at
least n repetitions
«Option-\
Delimiter«n1,n2»Delimits numberFind /[t]«2,4»/Select two to four tabs
standing for n to
n repetitions
[[Delimiter[...]Delimits a patternFind /[A-F]/Search for any character in the set A-F
\\Delimiter\r\Searches backwardsFind \alpha\Search backwards and select the word "alpha"
and selects regular
expression
]]Delimiter[...]Delimits a patternFind /[A-F]/Search for any character in the set A-F
``Delimiterc1 `c2` Sends output ofEcho Files command sends its output to Echo command,
command c2 to `Files -t TEXT`which prints the output on the screen
command c1 for
processing
{{Delimiter{v}Delimits variable vEcho "{MPW}"Echoes contents of shell variable {MPW}
}}Delimiter{v}Delimits variable vEcho "{MPW}"Echoes contents of shell variable {MPW}
Option-D
EscapenReturnEcho nEcho a return
Option-D
EscapetTabEcho nEcho a tab
Option-D
EscapefForm feedEcho nEcho a form feed
Option-D
Escape¬Defeats the meaningEcho ¬Output: ¬
of the special
character that
follows it
**Filename op.n*Matches zero orX*Match zero or more occurrences of character X
more occurrences of
the preceding
character or
character list
++Filename op.r+Matches one or moreX+Match one or more occurrences of character X
occurrences of the
preceding character
or characters
?*?* (same as )
Filename op.?*Matches any number
?*.cMatc any filename with the extension ".c"
of any characters
in a filename
¬Option-L
Filename op.[¬list]Matches any
[¬A-F]Match any character that is not in the set A-F
character not in
the list
»Option-Shift-\Filename op.«n»Delimits number [X]«2»Match two occurrences of the character X
standing for number
of repetitions
«Option-\Filename op.«n»Delimits number[X]«2»Match two occurrences of the character X
standing for number
of repetitions
[[Filename op.[...]Delimits a pattern[A-F]Match any character in the set A-F
]]Filename op.[...]Delimits a pattern[A-F]Match any character in the set A-F
Filename op. Matches any number .cMatch any filename with the extension ".c"
of any characters
in a filename
Option-D
Line cont.l  lIf  stands alone(First line:)Output: How are you today?
at end of a line,Echo “How are 
MPW joins line to(Second line:)
next line, ignoringyou today?”
return
""Make"s"Delimits a str in"{CLibraries}"The C runtime libraries
which each charCRuntime.o
is taken literally,
except for , {},
and ‘
##Make#sCharacters between### DependencyString following # is interpreted as a comment.
# and terminator rules ###
are interpreted as
a comment
''Make's'Delimits a string'{CLibraries}'The C runtime libraries
in which allCRuntime.o
characters are
taken literally
Option-D
Makel  lIf  stands alone(First line:)Output: Sample ƒƒ Sample.p.o Sample.r
at end of a line,Sample ƒƒ
MPW joins line toSample.p.o 
next line, ignoring(Second line:)
returnSample.r
ƒOption-F
Makef1 ƒ f1File f1 depends onSample.p.o ƒ File Sample.p.o depends on file Sample.p
file f2Sample.p
ƒƒOption-F
Makef1 ƒƒ f1File f1 depends onSample ƒƒFile Sample depends on file Sample.p.o, and
file f2, and f2 hasSample.p.oSample p.o. has its own set of build commands
its own build cmds
<<Redirection<fStandard input iAlert < ErrorsDisplay an alert dialog containing the contents
taken fromof the file Errors
filename f
>>Redirection>fRedirects standardEcho "{Status}" Write contents of shell variable {Status} to
output, replacing> Errorsfile Errors, replacing its previous contents
contents of file f
>>>>Redirection>>fRedirects standardEcho "{Status}"Append contents of shell variable {Status} to
output, appending>> Errorsthe end of file Errors
it to contents of
file f
Option->
Redirection fRedirects (Files .p ||) List filenames that end in ".p". Send diagno-
diagnostics, Errorstics to file Errors, replacing its contents
replacing contents
of file f
Option->
Redirection fRedirects(Files .p ||) List filenames that end in ".p". Append
diagnostics, Errorsdiagnostics to end of file Errors
replacing contents
of file f
Option-W
Redirection fRedirects both (Files .p ||) List filenames ending in ".p". Send output,
standard output and Tempdiagnostics to file Temp, replacing its
diagnostics tocontents
file f
Option-W
Redirection fRedirects both(Files .p ||)List filenames ending in ".p". Append
standard output and Tempoutput and diagnostics to file Temp
diagnostics to
file f
!~!~
Reg.expr.op."s1" !~ True if s1 is notEcho `Evaluate Output: 1
/s2/ equal to s2"alpha" !~
/beta/`
**
Reg.expr.op.r*Selects zero or Find /('*’')+Select a group of one or more asterisks
more occurrences of '/'[rt ]*/followed by a slash bar and 0 or more white
regular expressionspaces
++Reg.expr.op.r+Selects one or more Find /('*')+'/'/Select a group of one or more asterisks
occurrences of
regular expression
--
Reg.expr.op.c1-c2 Stands for rangeFind Select any word made up of upper- and
of characters/[A-Za-z]+n/lower-case letters that appears at the end
between c1 and c2of a line
=~=~
Reg.expr.op."s1" True if s1 is equal Echo `Evaluate Output: 1
=~ /s2/to s2"beta" =~
/beta/‘`
:Colon
Reg.expr.op.s:sAll text between Find •: Select (highlight) all text in file
(two selections)
Option-5
Reg.expr.op.cmd -c
(With command that Replace -c Replace string "123" with string "456" every
takes a -c option): /123/ 456time it appears in target window
Repeats command to
end of file
Option-5Reg.expr.op.r
Selects regularFind /arlie /Select the letters "arlie" at the end of a line
expression at the
end of a line
Option-8Reg.expr.op.•r
Selects regular Find /•ch/Select letters "ch" at the beginning of a line.
expression at the
beginning of a line
Option-;Reg.expr.op.c
Executes "Commando" TileWindows Invoke TileWindows Commando
command, invokes
Commando dialog
for command c
¬Option-L
Reg.expr.op.[¬list]Any character not Replace -c /Replace all characters except A-Z, a-z, returns
in the list[¬A-Za-zn" "]and spaces with asterisks
/ "*"
®Option-R
Reg.expr.op.r®nTags regular Replace /([a-zReverse the order of two words separated by one
expression with a A-Z]+)®1[ ]+([or more spaces
number (range: 1-9)a-zA-Z]+)®2/
'®2 ®1'
!!Selection!nSelects the lineFind !3Select the third line after the current
that is n lines selection
after end of
current selection
!!Selectionr!nPlaces insertion Find /alpha/!3Place insertion point three characters after
point n characters the word "alpha"
after regular
expression
¡Option-!
Selection¡nPlaces insertion Find ¡3Place insertion point three lines before start
point n lines before of current selection
start of current
selection
Option-5
Selection End of fileFind Place insertion point after last character in
file
§Option-6
Selection§Current selectionCopy §Copy the current selection (highlighted text)
to the Clipboard
Option-8
SelectionBeginning of fileFind •Place insertion point before first character in
file
Option-J
SelectionrPlaces insertion Find /charlie/Place insertion point before first character in
point before first the word "charlie"
char in regular
expression
Option-J
SelectionPlaces insertion Find /charlie/Place insertion point after last character of
point after last the word "charlie"
character of
regular expression
&&&&
Terminatorc1 && c2 Executes command c2Find /charlie/ If string "charlie" is found, MPW echoes,
if command c1 && Echo Found!"Found!"
succeeds
;;
Terminatorc ; cTreats commands oEcho hello ; Output: (First line:) Hello (Second line:)
the same line as if Echo goodbyeGoodbye
they were on
different lines
Return
Separates Terminatorc (r)Ends commandEcho Hello(r)Output: Hello
commands
||
Terminatorc1 | c2
Pipes output of Files | Count -lFiles pipes a list of files to Count, which
command c1 to prints the list on the screen
input of c2
||||
Terminatorc1 || c2Executes command c2 Find /zebra/ Searches for string "zebra" and echoes "Sorry!"
if command c1 fails|| Echo Sorry!if search fails
SpSpace
Whitespacew wSeparates wordsEcho HelloOutput: Hello
TabTab
Whitespacew wSeparates wordsEcho HelloOutput: Hello
??Wildcard
?Matches any single Find /Bar?/Select any four-character word that begins with
character in a "Bar"
string
?*?* (same as )
Wildcardchars?*Matches any number Find /Mar?*/Select any word that begins with "Mar"
of occurrences of
any character
(same as )
Option-X
Wildcard Matches any number Find /Mar /Select any word that begins with "Mar"
of any characters
in a string

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Fresh From the Land Down Under – The Tou...
After a two week hiatus, we are back with another episode of The TouchArcade Show. Eli is fresh off his trip to Australia, which according to him is very similar to America but more upside down. Also kangaroos all over. Other topics this week... | Read more »
TouchArcade Game of the Week: ‘Dungeon T...
I’m a little conflicted on this week’s pick. Pretty much everyone knows the legend of Dungeon Raid, the match-3 RPG hybrid that took the world by storm way back in 2011. Everyone at the time was obsessed with it, but for whatever reason the... | Read more »
SwitchArcade Round-Up: Reviews Featuring...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for July 19th, 2024. In today’s article, we finish up the week with the unusual appearance of a review. I’ve spent my time with Hot Lap Racing, and I’m ready to give my verdict. After... | Read more »
Draknek Interview: Alan Hazelden on Thin...
Ever since I played my first release from Draknek & Friends years ago, I knew I wanted to sit down with Alan Hazelden and chat about the team, puzzle games, and much more. | Read more »
The Latest ‘Marvel Snap’ OTA Update Buff...
I don’t know about all of you, my fellow Marvel Snap (Free) players, but these days when I see a balance update I find myself clenching my… teeth and bracing for the impact to my decks. They’ve been pretty spicy of late, after all. How will the... | Read more »
‘Honkai Star Rail’ Version 2.4 “Finest D...
HoYoverse just announced the Honkai Star Rail (Free) version 2.4 “Finest Duel Under the Pristine Blue" update alongside a surprising collaboration. Honkai Star Rail 2.4 follows the 2.3 “Farewell, Penacony" update. Read about that here. | Read more »
‘Vampire Survivors+’ on Apple Arcade Wil...
Earlier this month, Apple revealed that poncle’s excellent Vampire Survivors+ () would be heading to Apple Arcade as a new App Store Great. I reached out to poncle to check in on the DLC for Vampire Survivors+ because only the first two DLCs were... | Read more »
Homerun Clash 2: Legends Derby opens for...
Since launching in 2018, Homerun Clash has performed admirably for HAEGIN, racking up 12 million players all eager to prove they could be the next baseball champions. Well, the title will soon be up for grabs again, as Homerun Clash 2: Legends... | Read more »
‘Neverness to Everness’ Is a Free To Pla...
Perfect World Games and Hotta Studio (Tower of Fantasy) announced a new free to play open world RPG in the form of Neverness to Everness a few days ago (via Gematsu). Neverness to Everness has an urban setting, and the two reveal trailers for it... | Read more »
Meditative Puzzler ‘Ouros’ Coming to iOS...
Ouros is a mediative puzzle game from developer Michael Kamm that launched on PC just a couple of months back, and today it has been revealed that the title is now heading to iOS and Android devices next month. Which is good news I say because this... | Read more »

Price Scanner via MacPrices.net

Amazon is still selling 16-inch MacBook Pros...
Prime Day in July is over, but Amazon is still selling 16-inch Apple MacBook Pros for $500-$600 off MSRP. Shipping is free. These are the lowest prices available this weekend for new 16″ Apple... Read more
Walmart continues to sell clearance 13-inch M...
Walmart continues to offer clearance, but new, Apple 13″ M1 MacBook Airs (8GB RAM, 256GB SSD) online for $699, $300 off original MSRP, in Space Gray, Silver, and Gold colors. These are new MacBooks... Read more
Apple is offering steep discounts, up to $600...
Apple has standard-configuration 16″ M3 Max MacBook Pros available, Certified Refurbished, starting at $2969 and ranging up to $600 off MSRP. Each model features a new outer case, shipping is free,... Read more
Save up to $480 with these 14-inch M3 Pro/M3...
Apple has 14″ M3 Pro and M3 Max MacBook Pros in stock today and available, Certified Refurbished, starting at $1699 and ranging up to $480 off MSRP. Each model features a new outer case, shipping is... Read more
Amazon has clearance 9th-generation WiFi iPad...
Amazon has Apple’s 9th generation 10.2″ WiFi iPads on sale for $80-$100 off MSRP, starting only $249. Their prices are the lowest available for new iPads anywhere: – 10″ 64GB WiFi iPad (Space Gray or... Read more
Apple is offering a $50 discount on 2nd-gener...
Apple has Certified Refurbished White and Midnight HomePods available for $249, Certified Refurbished. That’s $50 off MSRP and the lowest price currently available for a full-size Apple HomePod today... Read more
The latest MacBook Pro sale at Amazon: 16-inc...
Amazon is offering instant discounts on 16″ M3 Pro and 16″ M3 Max MacBook Pros ranging up to $400 off MSRP as part of their early July 4th sale. Shipping is free. These are the lowest prices... Read more
14-inch M3 Pro MacBook Pros with 36GB of RAM...
B&H Photo has 14″ M3 Pro MacBook Pros with 36GB of RAM and 512GB or 1TB SSDs in stock today and on sale for $200 off Apple’s MSRP, each including free 1-2 day shipping: – 14″ M3 Pro MacBook Pro (... Read more
14-inch M3 MacBook Pros with 16GB of RAM on s...
B&H Photo has 14″ M3 MacBook Pros with 16GB of RAM and 512GB or 1TB SSDs in stock today and on sale for $150-$200 off Apple’s MSRP, each including free 1-2 day shipping: – 14″ M3 MacBook Pro (... Read more
Amazon is offering $170-$200 discounts on new...
Amazon is offering a $170-$200 discount on every configuration and color of Apple’s M3-powered 15″ MacBook Airs. Prices start at $1129 for models with 8GB of RAM and 256GB of storage: – 15″ M3... Read more

Jobs Board

*Apple* Systems Engineer - Chenega Corporati...
…LLC,** a **Chenega Professional Services** ' company, is looking for a ** Apple Systems Engineer** to support the Information Technology Operations and Maintenance Read more
Solutions Engineer - *Apple* - SHI (United...
**Job Summary** An Apple Solution Engineer's primary role is tosupport SHI customers in their efforts to select, deploy, and manage Apple operating systems and Read more
*Apple* / Mac Administrator - JAMF Pro - Ame...
Amentum is seeking an ** Apple / Mac Administrator - JAMF Pro** to provide support with the Apple Ecosystem to include hardware and software to join our team and Read more
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.