Topic 8 - Unix Shell Programming Flashcards
What is a shell script?
1) A computer program designed to be run by the Unix shell
2) a text file that can be read and understood by humans and by machines
What does a shell script contain?
1) Unix commands
2) Flow Control command
How are commands executed by the shell?
1) In order as they appear in the file or
2) in an order determined by the flow control statements
Different shells have different ______________
Different shells have different control structure syntaxes
How is a shell script created?
Like all high-level language programs, programmers create shell scripts with a text editor.
What is the main difference between shell scripts and high-level language programs?
Shell scripts do not have to be converted to machine language by a compiler - unix shell acts as an interpreter when reading script files.
What are the main uses of shell scripts?
1) To avoid repetition
2) To automate difficult tasks
There are two methods one can use to inform Unix which shell will be used to run the script. Describe the first method:
Calling the shell followed by the script file name - no need to set the permission of the script to executable.
There are two methods one can use to inform Unix which shell will be used to run the script. Describe the second method:
Invoking the shell as the first working line in the script file (using #!) - permission of the script must be set to executable.
With the second method of running a script, what happens when #1 is not present at beginning of first line?
a default shell will be used to run the script.
What happens if both methods are presented?
The first method has precedence
How can you assign the output of a command to a variable?
Using backquotes - example: #!/bin/sh files=`ls` echo $files - #!/bin/sh value=`expo 23456 + 6789` echo $value
What is the syntax for for loops?
for variable in value1 value 2... ; do ----command_set done; example: for i in 1 2 3; do ----exectueline done;
How do you debug your program?
use the -x when invoking the shell
or -xv
how are conditional statements done in bourne shell script?
Instead of evaluating a boolean variable to true or false, in born shell script, the only thing ou can test is whether a command is “successful” or “not successful”