Lecture8 - Lecture 8 Shell Programming Command substitution...

Info icon This preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Lecture 8 Shell Programming – C d b i i Command substitution Regular expressions and grep Use of exit, for loop and expr commands COP 3344 Introduction to UNIX 1
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Command Substitution a string in back quotes ` … ` does command substitution This means that the result of the command (the standard This means that the result of the command (the standard output of the command) replaces the back quoted string Examples: count=`wc -w <$1` # the value of count is assigned the number of words in file $1 if [ `wc -l < $2.txt` -lt 1000 ]; #checks if the number of lines in the file is < 1000 cat `grep -l exit *.sh` #print out all * sh files containing the word exit 2 #print out all *.sh files containing the word exit
Image of page 2
Exit Command (again) Conventionally, zero normally indicates success. Nonzero values indicate some type of failure It is Nonzero values indicate some type of failure. It is thus good practice to ensure that if the shell script terminates properly, it is with an “exit 0” d command. If the shell script terminates with some error that would be useful to a calling program terminate would be useful to a calling program, terminate with an “exit 1” or other nonzero condition. most Unix utilities that are written in C will also call “exit(<value>);” upon termination to pass a value back to the shell or utility that called that tilit 3 utility.
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon