Unix Shell Programming Lecture Review

0.0(0)
studied byStudied by 0 people
full-widthCall with Kai
GameKnowt Play
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/45

flashcard set

Earn XP

Description and Tags

Flashcards covering key vocabulary and concepts from the Unix - Shell Programming lecture, including shell basics, variables, command-line parameters, arithmetic, conditional statements (if, case), and looping constructs (for, while, until).

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

46 Terms

1
New cards

Shell Programming

The process of writing scripts, which are sequential lists of commands, using the shell as a programming language to automate tasks.

2
New cards

Shell Program

A program consisting of a sequential list of commands, effectively a listing of other programs to run in order.

3
New cards

Comment (Shell Script)

A line in a shell script starting with the '#' symbol, which is not processed by the shell and serves only to explain the code to humans.

4
New cards

Shebang Line

The first line of a shell executable, starting with '#!', which specifies which interpreter (e.g., /bin/bash, /usr/bin/perl) should be used to run the script.

5
New cards

Return Value (Exit Code)

An integer value returned by every program and shell to indicate success (0) or failure (non-zero, typically 1) of its execution.

6
New cards

Variable (Shell)

A container used to hold values in a shell script, supporting combinations of letters, numbers, and '', must start with a letter or '', and is case-sensitive.

7
New cards

Setting Variables (Shell)

Done using the '=' operator (e.g., d=date), does not require prior declaration, and all variables are treated as strings of characters.

8
New cards

Reading Variables (Shell)

Done by prefixing the variable name with '$' (e.g., $d or ${d}), which replaces the variable with its stored value.

9
New cards

Braced Variable Expansion (${VAR})

Used to explicitly define the boundaries of a variable name when it is directly followed by other characters, preventing the shell from looking for a longer variable name (e.g., ${Color}Sky).

10
New cards

read command

Reads values from standard input and assigns them to one or more specified variables.

11
New cards

Single Quotes ('')

Quotation marks that prevent the shell from interpreting any characters or variables within them; literally prints the enclosed content.

12
New cards

Double Quotes ("")

Quotation marks that allow for variable interpretation (expansion) within them, but generally prevent other special character interpretation.

13
New cards

Backticks (``)

Quotation marks that interpret variables and treat the enclosed content as a command to run, returning the output of that command (command substitution).

14
New cards

Command Line Parameters

Values passed to a shell script at the time of its execution, known before the script starts running, unlike user input.

15
New cards

$0 (Special Variable)

A special shell variable that holds the name of the running program (script).

16
New cards

$1-$9 (Special Variable)

Special shell variables that hold the first nine command-line arguments passed to the program.

17
New cards

$* (Special Variable)

A special shell variable that holds all of the command-line arguments as a single string.

18
New cards

$# (Special Variable)

A special shell variable that holds the total number of command-line arguments passed to the program.

19
New cards

Arithmetic in Shell

Variables containing numbers can be treated as numerical values and subjected to operations like addition, subtraction, multiplication, division, and modulo.

20
New cards

$(( )) Command

A shell construct used for performing integer arithmetic operations like +, -, *, /, and % (e.g., $(( 1 + 6 ))).

21
New cards

Control Flow Statements

Programming constructs in shell scripts that determine the order in which statements are executed, based on conditions or for repetitive tasks.

22
New cards

Conditional Statements

Statements in shell scripts that allow certain commands to be performed only if specific conditions are true.

23
New cards

test Command

A shell command used to check if certain conditions are true, often for comparisons or file system checks.

24
New cards

-eq (test condition)

A condition used with test for numerical equality comparison.

25
New cards

-ne (test condition)

A condition used with test for numerical inequality comparison.

26
New cards

-lt (test condition)

A condition used with test for numerical 'less than' comparison.

27
New cards

-le (test condition)

A condition used with test for numerical 'less than or equal to' comparison.

28
New cards

-gt (test condition)

A condition used with test for numerical 'greater than' comparison.

29
New cards

-ge (test condition)

A condition used with test for numerical 'greater than or equal to' comparison.

30
New cards

-d (test condition)

A condition used with test to check if a file is a directory.

31
New cards

-e (test condition)

A condition used with test to check if a file exists.

32
New cards

-f (test condition)

A condition used with test to check if a file is a normal file.

33
New cards

-s (test condition)

A condition used with test to check if a file is non-empty.

34
New cards

! (test condition)

A logical NOT operator used with test to negate the next condition check.

35
New cards

-a (test condition)

A logical AND operator used with test to combine two conditions, both of which must be true.

36
New cards

-o (test condition)

A logical OR operator used with test to combine two conditions, where at least one must be true.

37
New cards

[] (Shortcut for test)

A common shortcut syntax for the test command, enclosed in square brackets (e.g., [ -f tFile ] is equivalent to test -f tFile).

38
New cards

if then fi (Conditional Statement)

A basic conditional structure that executes a block of statements only if a given condition is true.

39
New cards

if then else fi (Conditional Statement)

A conditional structure that executes one block of statements if a condition is true, and a different block if the condition is false.

40
New cards

if then elif else fi (Conditional Statement)

A conditional structure that allows for multiple conditions to be checked sequentially. If the first condition is false, the next elif condition is checked, and so on, with an optional else for all other cases.

41
New cards

case esac (Conditional Statement)

A multi-way branch conditional statement that compares a string against multiple patterns and executes the statements corresponding to the first matching pattern.

42
New cards

Loops (Control Flow)

Programming constructs used to repeatedly execute a block of statements, either for a set number of times, while a condition is true, or until a condition is false.

43
New cards

for Loop (Shell)

A loop construct that iterates through a list of items, assigning each item to a variable and executing a block of statements for each item.

44
New cards

for Loop (Special Form)

A specific form of the for loop, without an explicit list, which iterates through all of the command-line arguments by default.

45
New cards

while Loop (Shell)

A loop construct that repeatedly executes a block of statements as long as a given condition remains true.

46
New cards

until Loop (Shell)

A loop construct that repeatedly executes a block of statements until a given condition becomes true.