Grouping commands, Using parentheses ( ), Using braces – HP NonStop G-Series User Manual

Page 37: Using parentheses ( ) using braces, Command-grouping symbols

Advertising
background image

3.

The output of grep r-x becomes the input to wc -l, which displays the number of files
matching the grep criteria in the standard input file.

To get the same results without using a pipeline, you would have to do the following:
1.

Direct the output of ls -l /user to a file:

$ ls -l >file1

2.

Use file1 as input for grep r-x and redirect the output of grep to another file:

$ grep r-x file1 > file2

3.

Use the output of grep as input for wc -l:

$ wc -l file2

12

Each command in a pipeline runs as a separate process. Pipelines operate in one direction only
(left to right), and all processes in a pipeline can run at the same time. A process pauses when it
has no input to read or when the pipe to the next process is full.

Grouping Commands

The OSS shell provides two ways to group commands, as shown in

Table 5

.

Table 5 Command-Grouping Symbols

Description

Symbol

The shell creates a subshell to run the grouped commands as a separate process.

( )

(parentheses)

The shell runs the grouped commands as a unit.

{ }

(braces)

Using Parentheses ( )

In the following command grouping, the OSS shell runs the commands enclosed in ( ) (parentheses)
as a separate process:

$ (cd reports;ls);ls

In this example, the shell creates a separate shell program (a subshell) that moves to the directory
/reports

and lists the files in that directory (cd reports;ls). After the subshell process finishes,

the shell lists the files in the current directory (ls).

If this command were written without the ( ), the original shell would move to the directory
/reports

, list the files in that directory, and then list the files in that directory again. There would

be no subshell and no separate process for the cd reports;ls command.

The shell recognizes the ( ) wherever they occur in the command line. To use parentheses literally
(that is, without their command-grouping action), place a \ (backslash) immediately before either
the ( (open parenthesis) or the ) (close parenthesis). (For more information, see

“Quoting”

(page 38)

.)

Using Braces { }

When commands are grouped in { }, the shell executes them without creating a subshell. In the
following example, the shell runs date, writing its output to the file todaygrp, and then runs who,
writing its output to todaygrp:

$ { date; who }>todaygrp

If the commands were not grouped together with braces, the shell would write the output of date
to the display and the output of who to the file todaygrp.

The shell recognizes { } in pipelines and command lists, but only if the { (left brace) is the first
character on a command line.

Command-Entry Aids

37

Advertising
This manual is related to the following products: