Shell Scripting Review Questions

Q. What are the two types of logical constructs mentioned in this chapter? A. The if and case constructs.


Q. What would != imply in a looping condition? A. != would check the value for non-equality.


Q. What is the function of the shift command? A. The shift command moves an argument to the left.


Q. You can script the startup and shutdown of a database. True or False? A. True.


Q. What is the difference between a line in a script starting with a “#” and a “#!”? A. The former is used to include general comments in the script and the latter combination dictates the full path to the shell file that is to be used to execute the script.


Q. What comments may you want to include in a shell script? Write any six. 6. The author name, creation date, last modification date, location, purpose, and usage.


Q. What is one benefit of writing shell scripts? 7. One major benefit of writing shell scripts is to automate lengthy and repetitive tasks.


Q. What are the three major components in a shell script? 8. The three major components in a shell script are commands, control structures, and comments.


Q. Which looping construct can be used to perform an action on listed items? 9. The for loop.


Q. What does the echo command do without any arguments? 10. The echo command inserts an empty line in the output when used without arguments.


Q. What would the command echo $? do? 11. This command will display the exit code of the last command executed.


Q. When would you want to use an exit code in your script? 12. The purpose of using an exit code is to determine exactly where the script quits.


Q. What would you modify in a shell script to run it in the debug mode? 13. We would specify -x as an argument to the shell path.


Q. What would the command bash -x /usr/local/bin/script1.sh do? 14. This command will execute script1.sh in debug mode.