BCCS199_Session_13 Flashcards
The read command reads input from…?
stdin.
The test keyword allows you to make…?
logical tests for branching, looping, etc.
Conditional statements in bash are available as …?
if…then…[else…]fi.
Loops can be implemented using…?
for…in…do…done.
Command arguments in bash scripts are available as…?
$1, $2, $3, etc.
The read command reads one line of text from…?
stdin.
Format of the read command….?
read var1 [var2 …]
The test keyword can be used to test certain conditions in…?
bash:
test condition
Appears usually in the context of an…?
if, while, or for statement.
test expressions for examining file attributes:
-d FILE : FILE exists, and is a directory.
-e FILE : FILE exists
-f FILE : FILE exists, and is a regular file
-r FILE : FILE exists, and is readable.
-w FILE : FILE exists, and is writable.
- x FILE : FILE exists, and is executable.
FILE1 -nt FILE2 : FILE1 is newer than FILE2
test expressions for comparing strings…?
[-n] STRING : the length of STRING is greater than zero.
-z STRING : the length of STRING is zero.
STRING1 = STRING2 : STRING1 and STRING2 are equal
STRING1 != STRING2 : STRING and STRING2 are not equal.
logic expressions for the test Command.
EXPRESSION1 -a EXPRESSION 2 : Both EXPRESSION1 and EXPRESSION2 are true.
EXPRESSION1 -o EXPRESSION2 : Either EXPRESSION1 or EXPRESSION2 is true.
! EXPRESSION : EXPRESSION is false.
Branching in bash…?
If condition then command(s) else command(s) fi
The for loop can be expressed like this…?
for VICTIM in list
do
statement(s)
done.
This will loop through every item in list, with $VICTIM representing each one in turn.
for loop example: #!/bin/bash
for F in ‘ls’
do
echo “Oh, look: there’s a file called $F in $PWD!”
done
- Takes the list of files in the current directory, and prints them out with a joyful comment.
- Note the
ls
, and the reference to the $PWD environment variable.