Tools: MPW
Advanced Search
Apple Developer Connection
Member Login Log In | Not a Member? Support

MPW Command Reference


Appendix C (continued)

Delimiters

" "  Enclose a literal string (with exceptions)

Double quotation marks, when used in pairs, enclose literal strings but with certain exceptions. Within double quotation marks, the characters , {, }, and ` are interpreted, not taken literally. Therefore, you can place special characters marked with the character, variables, and backquoted commands within double quotation marks.

For example, you would use double quotation marks with each of these commands:

Echo "∂tHello, world"
Echo "{test}"
Echo "`Files`"

Within a command, you can nest single quotation marks within double quotation marks, and double within single. However, you cannot nest double within double or single within single because the first two quotation marks in a command line are interpreted as a pair.

' '  Enclose a literal string (no exceptions)

Single quotation marks, when used in pairs, enclose literal strings. Each character within single quotation marks is taken literally, including , {, }, and `. For example, the command

Echo '{variable1}'

displays

{variable1}

instead of the current value of {variable1}.

You can enclose double quotation marks within single quotation marks if you want the double quotation marks to be taken literally and not as special characters. For example, the command

Echo '"hello"'

displays

"hello"

Within a command, you can nest double quotation marks within single quotation marks, and single within double. However, you cannot nest double within double or single within single because the first two quotation marks in a command line are interpreted as a pair.

( )  Group an expression or a command

Parentheses have two meanings--they can group parts of arithmetic, logical, or regular expressions, or they can group commands. The expression or command within parentheses is evaluated before the rest of the expression. If an expression contains more than one set of parentheses, each set is evaluated in order from left to right.

For example, in the command

Evaluate 4 * (8 - 2)

the expression (8 - 2) is evaluated first, and the result (which is 6) is multiplied by 4. If the parentheses were placed differently, the command would have a different result.

In the command line

Set largeFile `(Catenate smallFile || Echo Sorry!)`

the Catenate and Echo commands are grouped within parentheses so that they are evaluated first. The command line copies the contents of the file named smallFile to the variable {largeFile}, displaying "Sorry!" in the active window if the copy does not work.

` `  Pass output to another command

The ` ` characters, known as backquotes, enclose a command whose output is used as a parameter to another command. For example, in the command line

Count -l `Files -o -f -r -t TEXT HD:Sources:`

Files lists all of the files in the HD:Sources directory and in each subdirectory of this directory (the -r option specifies a recursive listing). This list of files is passed to the Count command which counts the number of lines in each file.

If the output of the command within backquotes contains single or double quotation marks, the quotation marks are interpreted as special characters and then discarded.

`` ``  Pass output, saving quotation marks

The `` `` characters, known as double backquotes, enclose a command whose output is used as a parameter to another command. If the output of the command within double backquotes contains single or double quotation marks, the quotation marks are taken as literal characters and remain in the output.

For example, in the command line

Print -h ``Files``

the Files command generates a list of files in the current directory and passes the list to Print, which prints it with headers. Because Files is placed within double backquotes, any quotation marks in the list of files remain intact.

\ \  Search backward

Backward slashes are used to search backward for strings or patterns. The command searches backward from the insertion point until it selects what you have specified or reaches the beginning of the file. For example, the command

Find \magic\

searches backward for the string "magic". If you want to start from the end of the file rather than at the insertion point, you can enter two commands like these:

Find ∞ ; Find \magic\

These commands find the end of the file, then search backward to find the first occurrence of the string "magic".

/ /  Search forward

Forward slashes are used to search forward for strings or patterns. The command searches forward from the insertion point until it selects what you have specified or reaches the end of the file. For example, the command

Find /shazam/

searches forward for the string "shazam". If you want to start from the beginning of the file rather than at the insertion point, you can enter two commands like these:

Find • ; Find /shazam/

These commands find the beginning of the file, then search forward to find the first occurrence of the string "shazam".

« »  Specify a repetition  [Option-\, Option-Shift-\]

The notation «n» is used after a scan set to locate the scan set when it occurs n times in succession. For more information on scan sets, see the [ ] Specify a scan set entry.

For example, you can write a statement that locates two adjacent tab characters with the command

Find /[∂t]«2»/

You can use the « » characters in three ways:

• «n» matches the pattern when it occurs exactly n times
• «n matches the pattern when it occurs at least n times
• «n1,n2» matches the pattern when it occurs at least n1 times and at most n2 times

For example, the command

Find /[∂t]«1,»/

matches any sequence of one or more tab characters, and the command

Find /[∂t]«1,4»/

matches a sequence of one, two, three, or four tab characters.

[ ]  Specify a scan set

Brackets enclose scan sets, which specify a list or a range of characters a command will search for. You should always place brackets within forward or backward slashes (to indicate a forward or backward search, respectively). For example, the command

Find /[abcxyz]/

selects any of the characters a, b, c, x, y, or z, in lowercase.

Note
Searches for individual letters in scan sets are always case sensitive. Searches for ranges of characters are case sensitive or not depending on whether you have set the {CaseSensitive} variable to true or false. By default, {CaseSensitive} is set to false, so searches for ranges are not case sensitive. •

To specify a range of characters within a scan set, type two characters separated by a hyphen, as in

Find /[a-f]/

which selects any of the characters A, B, C, D, E, or F, in lowercase or uppercase. You could also write

Find /$[0-9a-f]+/

which matches any hexadecimal number. In this pattern, the $ is a literal character which can be followed by a group of characters, including any of the numbers between 0 and 9, or any of the letters between A and F, lowercase or uppercase. The + character indicates that the group can contain one or more characters.

{ }  Enclose a variable

Whenever you use an MPW Shell command to obtain the value of a variable, you must place the variable name within braces. However, you do not use braces when you first define the variable with the Set command.

For example, the commands

Set number1 100
Set number2 50

define the variables {number1} and {number2} and assign them the values 100 and 50, respectively. In those commands, you do not use the braces. However, when you want to use the values of the variables in a command, as in

Evaluate {number1} + {number2}

you must use braces around the variable names. If you want to display the current value of a variable in the active window, you must use a command like

Echo {number1}

which would display 100 if that is the current value of {number1}. If you entered

Echo number1

the MPW Shell would display the string number1 in the active window--a very different result.

You do not need to place a variable name within braces if the command does not extract the value of the variable. For example, the command

Evaluate a += 2

increments the value of the variable {a} by 2.

If the value of a variable contains quotation marks, you must use double braces--{{ }}--to enclose it.

{{ }}  Enclose a variable, saving quotation marks

The {{ }} characters, known as double braces, enclose a variable whose value contains quotation marks that you do not want discarded. For example, suppose you enter

Set aVariable 'ab"c'

to define the variable {aVariable} and set its value to 'ab"c'. You would need to enter

Echo {{aVariable}}

to display the value of {aVariable} in the active window.

 
 


Last Updated July 2000