Chapter 11 Flashcards
A blank is a program written in an interpreted language, typically associated with a shell or other programs whose primary purpose is something other than as an interpreted language
script
In Linux, many scripts are blank, which are associated with Bash or another shell.
shell scripts
Shell scripts are blank, so you can create them in text editors, such as vi, nano, or pico
plain-text files
You shouldn’t use word processing programs to create shell scripts because they embed blank in the final document.
binary code
The first two characters of the command to a script are blank and is known as a blank
!
shebang
When you’re done writing the shell script, you should modify it so that it’s executable with the blank command.
chmod
One of the most basic features of shell scripts is the ability to blank
run commands
Aside from the shebang, the script looks like commands that you would normally type except for what?
scripts list complete paths
If your script produces a no such file or directory error, you can use the blank command where command is the offending file
which
Each command in a script ends in a blank symbol, which tells the script to go to the next line(command)
ampersand (&)
The blank commands, such as ls, mv, cp, and rm are often used in scripts.
file manipulation commands
The blank command locates files that contain the string you specify, or it displays the lines that contain those strings in a single file
grep
The blank command searches for a patterns based on filenames, ownership, and similar characteristics
find
The blank command extracts text from fields in a file
cut
The blank program provides many of the capabilities of a conventional text editor but via commands that can be typed at a command prompt or entered in a script
sed
The blank command is a tool to use when a script must provide a message to the user
echo
The blank command can be used to send email from within a script
Blank can help you expand the utility of scripts
variables
Variable’s blank can be passed as parameters to a script, generated internally to a script, or extracted from a script’s environment
values
Another type of variable that can be set from the output of a command is also identified by blank, but typically is given a name that at least begins with a letter
leading dollar signs
In addition to assigning variables with the equal sign, you can read variables from a standard input using the blank command
read
One special type of variable is an blank variable, which is assigned and accessed just like a shell script variable
environment variable
Can you set an environment variables in one script and use in another script?
Yes
Environment variables are often used in blank scripts
shell startup scripts
The blank variable holds the exit status of the most recently executed command, which is an integer (usually 0) when terminated normally
$?
Scripting languages support several types of blank, which enable a script to perform one of several actions contingent on some condition
conditional expressions
The conditional expression uses blank around the condition
square brackets
One common command that uses conditional expressions is the blank command
if
An alternative form for a conditional expression uses the blank keyword rather than square brackets around the conditional
test
If more than two outcomes are possible, you can use blank
case
Give the syntax for case
case word in
pattern1) command(s) ;;
pattern2) command(s) ;;
…
esac
For a case statement, word is likely to be a blank, and each pattern is a possible blank of the word
variable
value
Each set of commands of a case statement must end with blank, and the case statement as a whole ends in the string blank
;;
esac
In a case statement, if you want to have a blank, use a * as the final pattern, which matches any word, so the command will execute if no other pattern matches
default condition
Conditional expressions are sometimes used in blank, which are structures that tell the script to perform the same task repeatedly until some condition is met
loops
What command used with the for loop can generate a specific number of lines
seq
Another type of loop is the blank loop, which executes as long as its condition is true
while
A blank is a part of a script that performs a specific subtask and that can be called by name from other parts of the script
function
Functions are defined by placing blank after the function name and enclosing the lines that make up the function with blank
parentheses
curly brackets
myfn() {
commands
}
Ordinarily, a script’s exit status is the same as the last command the script called – that is, the script returns blank
$?
You can control the exit value, or exit at any point by using the blank command
exit
Exiting a command with a certain numeric value helps you in blank research
error
If you use a variable to store the exit number, what should the syntax be for exiting
exit $variable
After using a text editor to create a shell script, what step should you take before trying to use the script by typing its name.
A) Set one or more executable bits using chmod
B) Copy the script to the /usr/bin directory
C) Compile the script by typing bash scriptname
D) Run a virus checker on the script
E) Run a spell checker on the script
A
Describe the effect of the following short script, cp1, if it’s called as cp1 big.c big.cc:
#!/bin/bash
cp $2 $1
A) It has the same effect as the cp command - copying the contents of big.c to big.cc
B) It compiles the c program and calls the result big.cc
C) It copies the contents of big.cc to big.c and eliminates old big.c
D) It converts the C program big.c to C++ big.cc
E) The script’s final line is invalid, so it won’t work
C
What is the purpose of conditional expressions in shell scripts?
A) They prevent scripts from executing if license conditions aren’t met
B) They display information about the script’s computer environment
C) They enable the script to take different actions in response to variable data
D) They enable scripts to learn in a Pavlovian manner
E) They cause scripts to run at only certain times of day
C
True or False: a user types myscript laser.txt to run a script called myscript. Within myscript, the $0 variable holds the laser.txt
False
True or False: Valid looping statements in Bash include for, while, and until
True
True or False: The following script launches three simultaneous instances of the terminal program.
#!/bin/bash
terminal
terminal
terminal
False
You’ve written a simple shell script to do nothing but launch programs. to ensure the script works with most user shells, the first line is blank
!/bin/bash
The blank Bash scripting command is used to display prompts for the user in a shell script.
echo
The blank bash scripting command is used to control the program flow based on a variable that can take many values
case
The blank Bash scripting command controls the return value generated by a script, independent of the other commands used in the script
exit