Week 10: Shell Environments / Programming / Makefiles Flashcards

1
Q

The shell environment consists of a set of _____ with _____

A

Variables with values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Shell variables are used by putting _ in front of their names

A

$ in front of their names:

$HOME

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

The two kinds of shell variables are:

A

Environment variables: available in the current shell and the programs invoked by the shell

Regular shell variables: not available by programs invoked in this shell

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

In bash, REGULAR variables are defined by:

A

varname=varvalue

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

In bash, environment variables are called

A

“exported variables”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Environment variables are defined by:

A

MYENVVAR=”env var”
export MYENVVAR

or

export MYENVVAR=”env var”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

To clear an environment variable, simply use…

A

unset

ex: unset varname;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

In csh and tcsh to create REGULAR variables, use…
To delete them….

A

set

ex: set VARNAME=”var”

unset

ex: unset VARNAME

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

In csh and tcsh to create environment variables, use

A

setenv WITH NO EQUALS SIGN

ex: setenv VARNAME “var”

unsetenv

ex: unsetenv VARNAME

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What do the following shell variables mean:

SHELL
PATH
LANG
USER
HOME
TERM
DISPLAY
HOSTNAME

A

SHELL: the name of the shell being used

PATH: where to find executables to execute

LANG: the locale you are using

USER: the user name of the user logged in

HOME: the user’s home directory

TERM: the kind of terminal the user is using

DISPLAY: where X program windows are shown

HOSTNAME: the name of the host logged on to

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

In UNIX, single quotes do what

A

Stop the expansion of a variable:

echo “Welcome $HOME”
Welcome /home/Connor

echo ‘Welcome $HOME’
Welcome $HOME

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

In UNIX, backwards quotes do what

A

Replace the variable with what is returned from the execution of the command

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Unix automatically searches for executables in…

A

Whatever is specified by the variable PATH

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

In Unix, do executables automatically execute from the current durectory?

A

NO

use: ./ to specify the current directory using the .

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

If there are multiple versions of a command, Unix executes them in the order of …

A

Left to right

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How does the alias command work, syntax?

A

alias alias-name=’real-command’

Where alias-name is one word and real-command can be separated by spaces

17
Q

A shell script is basically

A

A UNIX file with shell commands in it

18
Q

Why write shell scripts?

A

To automate difficult processes
and to avoid repetition

19
Q

In order to run a shell script, you must first

A

chmod the files in order to make them executable

chmod u+x myencrypt mydecrypt

20
Q

The syntax of a for loop in bash is:

A

for var in value1 value2 …
do
command_set
done

22
Q

The syntax of an if statement in bash is

A

if

then

fi

23
Q

An if, elif script looks like…

24
Q

Semicolons in scripts are used to…

A

Seperate statements on the same line:

if grep “UNIX” myfile; then echo “Got it”; fi

25
A colon in shell scripts are meant for...
nothing, they do nothing
26
What is the syntax of the test command?
test -(file type) file ## Footnote test –f file does file exist and is a regular file? test -d file does file exist and is a directory? test –x file does file exist and is executable? test –s file does file exist and is longer than 0 bytes?
27
What does "test -d" do?
Does the file exist and is it a directory?
28
What does "test -r" do?
Does the file exist and is it a regular file?
29
What does "test -x" do?
Does the file exist and is it an executable?
30
What does test -s do?
Does the file exist and is it longer than 0 bytes?
31
What are the three types of string tests?
test -z - Test whether or not the string has 0 characters in it test str1 = str2 - Is str1 equal to str2 test str != str2 - Not equal?
32
What are the following options for integer tests? -eq, -ne, -lt, -le, -gt, -ge
-eq, -ne, -lt, -le, -gt, -ge equal, not equal, less than, less than or equal to, greater than, greater than or equal to
33
In shell scripts, how many command line arguments can be taken?
$1 up to $9
34
In unix shell commands, the shift command...
Shifts all the command arguments to the left
35
In shell scripts, the read command...
Reads iput from the terminal: read var1 var2 var3 Action: reads a line of input from standard input Assign first word to var1, second word to var2, ... The last variable gets any excess words on the line.
36
In shell scripts, the case syntax is in the form of...