bash
, in particular)Both are open today from 11 AM to 11:55 PM. Go to the class moodle to take the quiz.
bash
, also know as the Bourne-Again SHell, since the oldest shell, sh
, is known as the Bourne shell after its creator.$ x=ken
$ echo x
$ echo $x
$ echo ${fruit[0]}
$ echo ${#fruit[*]}
$ fruit[1]=oranges
$ echo ${fruit[*]}
bash
can invoke a command and include its output in the current command$ d=$(date)
$ echo $d
would print something like: Tue Aug 15 11:06:22 MDT 2006$ dirname=$(basename $(pwd))
pwd
command to print the path of the current directory and then passes that directory to the basename
command and then assigns the result of THAT command in the variable dirnamebash
is asked to retrieve the value of such a variable, it strips out runs of whitespace and replaces them with a single space. To prevent bash
from doing this, you need to surround the variable in double quotes.$ output=$(cal)
$ echo $output
$ output=$(cal)
$ echo "$output"
September 2006
S M Tu W Th F S
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
bash
can redirect the output AND input of commands$ date
$ date > today
$ more today
$ rev < today
#!/bin/bash
x=$( ps )
echo "$x"
(
x=$( ps )
echo "$x"
)
echo "$x"
#!/bin/bash
x=$( ps )
echo "$x"
{
y=$( ps )
echo "$y"
}
echo "$y"
bash
can cause the output of one program to be sent as the input of another program via the pipe character
ls
command fail?exit
command
bash
has a set of input characters that have special meaning to it. These characters, known as metacharacters, include:
Metacharacter | Name | Meaning |
---|---|---|
\ | backslash | interpret the next character literally |
& | ampersand | execute a command in the background |
; | semicolon | separates commands |
$ | dollar sign | access a variable's value |
? | question mark | matches for a single character |
* | asterisk | matches for zero or more characters |
[] | square brackets | matches one of a set of characters |
( ) | parens | executes commands in a subshell |
{ } | curly braces | executes commands in the current shell or performs brace expansion when matching file names |
< and > | less than and greater than | input and output redirection |
| | pipe | connects the output stream of process A with the input stream of process B |
\n | newline | command termination |
\t | space or tab | word delimiter |
bash
know that it should leave them alone.
$ echo $((10 + 5))
echo $(((12 * 5) + (330 - 30)))
echo $((24 / 5))
if command
then
command(s)
fi
if command
then
command(s)
else
command(s)
fi
if command
then
command(s)
elif command
then
command(s)
elif command
then
command(s)
else
command(s)
fi
case variable in
value1)
command(s)
;;
value2)
command(s)
;;
*)
command(s)
;;
esac
for variable in word_list
do
command(s)
done
while command
do
command(s)
done
until command
do
command(s)
done
select
, shift
, break
, and continue
, see the Quigley textbook.fg
command or you can start it running again in the background with the bg
commandjobs
commandProjects emerge from the tar pit with running systems but most missed goals, schedules, and budgets
No one thing seems to cause the difficulty—any particular paw can be pulled away. But the accumulation of simultaneous and interacting factors brings slower and slower motion.
The Evolution of a Program
Program | Programming System |
Programming Product | Programming System Product |
Definitions
Term | Definition |
---|---|
Program | An executable that “is complete in itself, ready to be run by the author on the system on which it was developed. That is the thing commonly produced in garages, and that is the object the individual programmer uses in estimating productivity.” |
Programming Product | “This is a program that can be run, tested, repaired, and extended by anybody. It is usable in many operating environments, for many sets of data. [It] must be written in a generalized fashion...” such that it can take a wide range of input and it must also be thoroughly tested. Finally, it must be thoroughly documented. |
Programming System | “This is a collection of interacting programs, coordinated in function and disciplined in format, so that the assemblage constitutes an entire facility for large tasks. To become a programming system component, a program must be written so that every input and output conforms in syntax and semantics with precisely defined interfaces. … Finally, the program must be tested with other system components, in all expected combinations.” |
Programming System Product | All of the above! |