0% found this document useful (0 votes)
23 views

The Sequence: 2.8 Command Grouping

This document discusses shell script debugging techniques. It describes using the 'set -v' command to print lines as they are read, which helps isolate syntax errors. It also explains using 'sh -v proc' to invoke verbose mode without modifying the procedure. Debugging is further aided by the '-n' flag to prevent command execution and check for syntax errors. Grouping commands with curly braces or parentheses allows executing them in separate processes or changing directories.

Uploaded by

arunabhatla
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

The Sequence: 2.8 Command Grouping

This document discusses shell script debugging techniques. It describes using the 'set -v' command to print lines as they are read, which helps isolate syntax errors. It also explains using 'sh -v proc' to invoke verbose mode without modifying the procedure. Debugging is further aided by the '-n' flag to prevent command execution and check for syntax errors. Grouping commands with curly braces or parentheses allows executing them in separate processes or changing directories.

Uploaded by

arunabhatla
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

*)

if test -f $i then ln $i junk$$; rm junk$$ elif test $flag then echo file \'$i\' does not exist else >$i fi esac done

The -c flag is used in this command to force subsequent files to be created if they do not already exist. Otherwise, if the file does not exist, an error message is printed. The shell variable flag is set to some non-null string if the -c argument is encountered. The commands
ln ...; rm ...

make a link to the file and then remove it thus causing the last modified date to be updated.

The sequence
if command1 then command2 fi

may be written
command1 && command2

Conversely,
command1 || command2

executes command2 only if command1 fails. In each case the value returned is that of the last simple command executed.

2.8 Command grouping


Commands may be grouped in two ways,
{ command-list ; }

and
( command-list )

In the first command-list is simply executed. The second form executes command-list as a separate process. For example,
(cd x; rm junk )

executes rm junk in the directory x without changing the current directory of the invoking shell.

The commands
cd x; rm junk

have the same effect but leave the invoking shell in the directory x.

2.9 Debugging shell procedures

The shell provides two tracing mechanisms to help when debugging shell procedures. The first is invoked within the procedure as
set -v

(v for verbose) and causes lines of the procedure to be printed as they are read. It is useful to help isolate syntax errors. It may be invoked without modifying the procedure by saying
sh -v proc ...

where proc is the name of the shell procedure. This flag may be used in conjunction with the -n flag which prevents execution of subsequent commands. (Note that saying set -n at a terminal will render the terminal useless until an end- of-file is typed.)

The command

You might also like