Grouping And Combining Commands - Novell LINUX ENTERPRISE SERVER 11 - ADMINISTRATION Administration Manual

Hide thumbs Also See for LINUX ENTERPRISE SERVER 11 - ADMINISTRATION:
Table of Contents

Advertisement

5.6 Grouping And Combining
Shells allow0.0 you to concatenate and group commands for conditional execution.
Each command returns an exit code which determines the success or failure of its oper-
ation. If it is 0 (zero) the command was successful, everything else marks an error which
is specific to the command.
The following list shows, how commands can be grouped:
Command1 ; Command2
executes the commands in sequential order. The exit code is not checked. The fol-
lowing line displays the content of the file with cat and then prints its file properties
with ls regardless of their exit codes:
cat filelist.txt ; ls -l filelist.txt
Command1 && Command2
runs the right command, if the left command was successful (logical AND). The
following line displays the content of the file and prints its file properties only,
when the previous command was successful (compare it with the previous entry
in this list):
cat filelist.txt && ls -l filelist.txt
Command1 || Command2
runs the right command, when the left command has failed (logical OR). The fol-
lowing line creates only a directory in /home/wilber/bar when the creation
of the directory in /home/tux/foo has failed:
mkdir /home/tux/foo || mkdir /home/wilber/bar
funcname(){ ... }
creates a shell function. You can use the positional parameters to access its argu-
ments. The following line defines the function hello to print a short message:
hello() { echo "Hello $1"; }
You can call this function like this:
hello Tux
50
Administration Guide
Commands

Advertisement

Table of Contents
loading

This manual is also suitable for:

Suse linux enterprise server 11

Table of Contents