CNIT 340 Exam 2

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

what is generally the path to set the shell for a script to BASH?

#!/bin/bash

what is the syntax to enable debugging on the first line of the script?

#!/bin/bash <debugging options>

what is the preferred syntax for command substitution?

$(command)

what is the naming scheme for parameters for a function?

$1, $2, $3...

what is the syntax to get all arguments concatenated together space delimited?

$@

what is the syntax to access the value in a variable?

$VAR

what is the syntax to output the number of elements in an array?

${#VAR[@]}

what is the syntax for substitute when set?

${VAR:+val}

what is the syntax for default value substitution

${VAR:-val}

what is the syntax for default value assignment

${VAR:=val}

what is the syntax for null value error?

${VAR:?message}

what is the syntax to output all the elements of an array as a single string?

${VAR[*]}

what is the syntax to output all the elements of an array as a list?

${VAR[@]}

what is the syntax to access a specific element in an array?

${VAR[INDEX]}

what is the $VAR short for?

${VAR}

what are the different kinds of compound tests for double bracket testing

&&, ||, <, >

what is the preferred way to do arithmetic tests?

(( )) notation

what is the double parenthesis syntax to test if two integers are equal?

(( INT1 == INT2 ))

what is the syntax to perform integer math

(( expression ))

what is the syntax to match anything that is not already matched

*)

what is the flag if a file exists and is owned by the effective GID?

-G

what is the flag if a file exists and is owned by the effective UID

-O

what is the flag if a file exists and is set to the effective GID?

-g

what is the flag if a file exists and is a symlink?

-h or -L

what is the flag if a file exists and has read permission?

-r

what is the flag if a file exists and has its UID bit set?

-u

what is the flag if a file exists and has write permission?

-w

what is the flag if a file exists and has execure permission?

-x

what files does BASH parse if using a login shell?

.bash_profile, .bash_login, .profile

what files does BASH parse if used a non-login interactive shell?

.bashrc

what is the general syntax to match a single word?

/STRING /

what is the syntax for $ in REGEX?

/STRING$/

what is the general syntax for matching regular characters?

/STRING/

what is the syntax for ^ in REGEX?

/^STRING/

what is the flag to set the where an app will display to?

/dir/app -display host.domain:x.y

what does a TRUE value evaluate to in UNIX?

0

what is usually returned when a command sucessfully completes?

0

how many IO streams does every UNIX program have available?

3 I/O streams

how many commands are needed for a while loop?

3 commands

what is the max recommended depth for nesting loops?

4 deep

what can a function return?

8 bit integer (0-255)

how many registers are there in REGEX?

9

what is the default shell for most Linux distributions?

BASH

what is the syntax to enable debugging for a script

DEBUG=true ./script.sh

what is the command to trick the remove X client is a local X client?

DISPLAY=localhost:0.0

what happens if the FIRST is omittied in seq?

FIRST defaults to 1

what is the format of the DISPLAY XWin variable?

FQDN:x.y

what is the syntax to call a function?

FUNC ARG1 ARG2

what is the preferred syntax for defining a function?

FUNC() { CODE }

what is the syntax to change the prompt in a select loop?

PS3="MESSAGE"

what happens if the STEP is omitted in seq?

STEP defaults to 1

what is the syntax to store the output of command substitution as a single space separated value?

VAR=$(command)

what is the syntax to stored the output of command substitution as an array?

VAR=($(command))

what is the syntax to set multiple values in an existing array?

VAR=([INDEX1]=val1 [INDEX2]=val2)

what is the syntax to set multiple values at a time when creating an array/

VAR=(val1 val2 val2)

what is the syntax to define a scalar variable?

VAR=val

what is the syntax to set a value in an array?

VAR[INDEX]=val

what is the syntax to negate a basic test?

[ ! ]

what is the syntax to basic test if a file exists and it's a directory?

[ -d file ]

what is the syntax to basic test if a file exists?

[ -e file ]

what is the syntax to basic test if a file exists and it's a regular file?

[ -f file ]

what is the syntax to basic test if a string length is nonzero?

[ -n STRING ]

what is the syntax to basic test if a file exists and its size is greater than zero?

[ -s file ]

what is the syntax to basic test if a string length is zero?

[ -z STRING ]

what is the syntax to AND a basic test?

[ EXP1 -a EXP2 ]

what is the syntax to OR a basic test?

[ EXP1 -o EXP2 ]

what is the syntax to basic test if two integers are equal?

[ INT1 -eq INT2 ]

what is the syntax to basic test if INT1 is greater than or equal to INT2?

[ INT1 -ge INT2 ]

what is the syntax to basic test if INT1 is greater than INT2?

[ INT1 -gt INT2 ]

what is the syntax to basic test if INT1 is less than or equal to INT2?

[ INT1 -le INT2 ]

what is the syntax to basic test if INT1 is less than INT2?

[ INT1 -lt INT2 ]

what is the syntax to basic test if two integers are not equal?

[ INT1 -ne INT2 ]

what is the syntax to basic test if two strings are not equal?

[ STRING1 != STRING2 ]

what is the syntax to basic test if a two strings are equal?

[ STRING1 = STRING2 ]

what are the three kinds of test constructs

[ ], [[ ]], (( ))

what is the syntax to basic test if file1 is newer than file2

[ file1 -nt file2 ]

what is the syntax to basic test if file1 is older than file2

[ file1 -ot file2 ]

what is the syntax to negate a glob char set?

[!]

what is the syntax to glob a character range of only numbers and lowercase letters?

[0-9a-z]

what is the preferred syntax for arithmetic expressions?

[[ ]] or (( ))

how to match $ in REGEX

\$

what is the syntax to save a match to a register?

\(regex\)

how match match with contents of a register

\1 for first register

what is the syntax to match for word boundaries?

\< >\

how to match \ in REGEX

\\

what is the tranditional syntax for command substitution?

`command`

what is a XWin display

a keyboard and monitor combination

what is a shell script?

a list of shell commands

window manager

a special client that controls the appearance of the X display and moves, resizes, iconifies applications

what is sed?

a stream editor that based on ed and cannot be used interactively, must be used on a file or piped into

what is a XWin screen?

a virtual desktop

what is quoting?

a way to use meta-characters literally

grep -n

add line numbers

strong quote (')

all meta characters between the single quotes lose their meaning; must be escaped to use literally

weak quoting (")

all meta characters except $ and ' lose their meaning; must be escaped to use literally

sed -e

allows for multiple regexs, one -e per regex

where can the [char set] meta glob be used?

alone, prefix, suffix, both

what is returned when a variable is not set?

an empty string

what are the two subsets of meta characters?

anchor and modifiers

what does the following char set match: [!a-z]*

any string that does not start with a lowercase letter

what does each server have at least one of?

at least one display

what must each display have at least one of?

at least one screen?

what does break in loop control do?

breaks/exits a loop

array variable

can hold multiple elements at a time

how can XWin be secured?

can increase security via SSH tunneling

scalar variable

can only hold one element at a time

what can you do with a reserved variable?

can use the values stored in it, but cannot set the values in it

what is the syntax for a case statement?

case $VAR in PATTERN1) CODE ;; PATTERN2) CODE ;; esac

grep -i

case insensitive match

which is more common, recursion or chaining?

chaining

what are meta characters in REGEX?

characters with special meanings; wildcards

what is the architecture of X Windows?

client-server model

escape sequence

codes that have no associated keyboard key

what are the lines that don't start with + when shell tracing is enabled?

command results lines sent to stdout

what is the syntax for grep when piping

command | grep options searchtime

what is the syntax for sed when piping?

command | sed '/pattern/action'

what can be used within a conditional?

commands and expressions

-nv no exec verbove

copies every line to STDOUT but does not execute

sed d action

deletes matches from the output, but does not touch the original file

anchor

desgnates the postion in the line of text that the REGEX it so match

what commands does every loop have?

do and done

what is best practice when using xdm?

do not start xdm automatically until you're certain about the config of the x-server

what is the best practice for filenames

don't use meta characters

what is the syntax to print the value of an array

echo ${VAR[INDEX]}

what is the work around to return a string or a larger number for a function?

echo the return value, use command substitution to call the function, then use double bracket comparison to check if equal to value

what must a user-defind variable start with?

either a letter or underscore

what can the condition be for a while loop or until loop?

either a test or a command

how to change original file with sed

either use redirects to put into file, or use -i flag

-x debugging option

enable shell tracing, displays commands and arguments as executed

what is always needed at the end of a case statement?

esac

how can seq be used in a for loop?

execute using command substitution

what is the syntax to popluate a variable to a subshell?

export VAR

T/F [ ] and [[ ]] cannot be used for string and arithemtic comparisons?

false

T/F a read-only variable can be deleted using unset

false

T/F a user-defined variable can start with a number

false

T/F an array must start at 0

false

T/F arrays must be assign/set in ordinal/sequential order

false

T/F command substitution cannot be used as arguments for other commands

false

T/F is it possible to export a variable to its parent shell

false

T/F sed d action affects the original file

false

T/F the [char set] meta glob can match zero characters

false

T/F you can use a $ when defining a variable

false

T/F the cart (^) has the same meaning inside double brackets and outside double brackets in REGEX

false, it negates the chars inside a char set

T/F a line will be matched be matched if it only contains the expression

false, it will be matched if the expression is anywhere in the line

T/F rm wal*mart.txt will erase the file named wal*mart.txt

false, it will erase any file beginning with wall and ending with mart

T/F you include a $ when defining a standard for loop

false, the VAR gets set each iteration of the loop

T/F a line cannot contain different types of quoting

false; can use mulitple quoting types

T/F ls chapter??.doc will return chapter1.doc

false; does not match zero characters

T/F the * meta globbing character will match every filename

false; will only match visible filenames

T/F window manager is the same thing as XWin

false; window manager works on top of XWin

what is always needed at the end of a if/then statement?

fi

what is the order when parsing in a basic test?

first come first serve/left to right

what is the general way to do arithmetic expressions with basic tests?

flags instead of mathmatical symbols

what is the syntax for three expression for loops?

for (( INIT; CONDITION; COUNTING )) do CODE done

what is the syntax of using seq in a for loop?

for VAR in $(seq FIRST STEP STOP)

what is the syntax for a standard for loop?

for VAR in SET do CODE done

where must functions be placed?

function must be defined before it is called, so typically at the top of the script

what is the default scope for a function variable?

global

what is the default scope for a variable?

globally scoped

what is the syntax for grep

grep options searchterm file

what is best practice when defining a variable?

having it be in all caps

what is the set in a standard for loop

horizontal space delimited list of values

what is the syntax for a if/elif/else statement?

if STATEMENT then CODE elif STATEMENT then CODE else CODE fi

what is the syntax for a if/else statement?

if STATEMENT then CODE else CODE fi

what is the syntax for a block if/then statement?

if STATEMENT then CODE fi

what is the syntax for a one line if/then statement?

if STATEMENT; then ACTION; fi

what is the syntax for a basic test?

if [ statement ]

what is the syntax for a BASH extended test?

if [[ statement ]]

what is substitute when set?

if the variable is set, the the expression is replaced by the value

what is null value error?

if the variable is unset, then the message is printed to STDERR

what is default value assignment?

if the variable is unset, then the value is stored in the variable

what is default value substitution?

if the variable is unset, then the value replaces the expression

what are the two kinds of conditionals?

if/then and case

where do functions run?

inside the current shell

what happens when the solution for simple integer math is a decimal?

it will be rounded down/truncated

what are the default destinations for stdin, stdout, and stderr?

keyboard and display

what can a user-defined variable name contain?

letters, numbers, underscore character

what are the lines that start with + when shell tracing is enabled?

lines that the shell executed

select loop

list set of choices from which the user makes a selection

what is the syntax to make a variable local?

local VAR=val

what does ? in REGEX do?

matches 0 or 1 previous REGEX

what does + in REGEX do?

matches 1 or more previous REGEX

what does . do in REGEX?

matches a single character, even in the middle of a word

? meta globbing character

matches any character one time

* meta globbing character

matches any character zero or more times

what does .* do in REGEX?

matches any characters

what does this match: /.\{4\}$/

matches any lines where the last word is 4 letters long

what does \{min,max\} do in REGEX?

matches chars repeated between min and max times

what does \{min\} do in REGEX?

matches exactly min characters

what does [chars] do in REGEX?

matches if a char is in the [char]

what does [^chars] do in REGEX?

matches if the char is NOT in [char]

what does this match: /[a-z]\{5,7\}/

matches strings that are only lower case and contain 5 to 7 letters

what does this match: /[A-Za-z]\{4,\}/

matches strings that contain upper or lower case and are at least 4 chars long

[char set] meta globbing character

matches the characters stated one time

what does ^ do in REGEX?

matches the string if it is the first character(s) in a line

what does $ does in REGEX?

matches the string if it is the last character(s) in a line

what does \{min,\} do in REGEX?

matches words at least min chars long

what does * do in REGEX?

matches zero or more of the previous character

what are functions?

min scripts with own arguments and return codes

what is a function similar to?

more similar to a subroutine than a traditional function

what happens each time \(regex\) is used?

moves onto the next register

\n sequence

new line

what does command substitution return by default?

newline separated lists as a single space separated value

-n debugging option

no execute, read lines but don't execute, performs syntax checking

what are the features of XWin

not part of OS, architecture independent, network transparent, policy/style free

what are regular characters in REGEX?

numbers, letters, spaces, underscores; a REGEX may contain only regular characters

how does one do sed substitution on all lines?

omit pattern 1

what does this do: sed '/[0-9]/s/[0-9]*$/\$&/'

on any lines that contain a number, substitute any patterns that end with numbers with a $ and the original pattern

what are the two ways to enable debugging?

on the first line of the script, or at will within the script body

what does /xx*/ match?

one or more of the char x

what does this do: /^\(.\).*\1$/

only matches if the first and last characters of a line are the same

grep -l

only print filesnames with match (must have multiple files specified)

grep -v

only prints lines that do not match

sed -n p action

only prints lines that match

for loop

perform code once for each item in a list

until loop

perform code until a condition becomes true

while loop

perform code while a condition is true

where can the * meta globbing character be used at?

prefix, suffix, both

where can the ? meta globbing character be used at?

prefix, suffix, both

sed p action

prints all lines in addition to printing the matching lines

what is the seq program?

program that creates a sequence of space delimited values

What is the X Protocol?

protocol used to allow communication between server and client

what is xlib?

provides functions for connecting to a display server, creating windows, drawing graphics, responding to events

what does & do in sed

put what the pattern 2 match was here

single escape (/)

quotes/escaping the following character only; must be escaped to use literally

what is the syntax to make a variable read-only?

readonly VAR

how does sed substitution work?

replaces pattern 2 with pattern 3 on lines that that match pattern 1, does not affect the original file

what are variables that start with a number

reserved variable

egrep

run grep -E

what are the two types of shell variables?

scalar and array

what does the .xinitrc file do?

script that lauchges windows at login time on a system wide basis

what is the syntax for sed substitution

sed '/pat1/s/pat2/pat3

how does one substitute all matches on a line with sed

sed '/pat1/s/pat2/pat3/g'

what is the syntax for sed?

sed '/pattern/action' file

what is the syntax to print specific lines using sed?

sed -n 'start,endp' file

what is the syntax for select loop?

select VAR in ITEM1, ITEM2, ITEM3 do CODE done

what is the syntax for seq

seq START STEP STOP

what is the syntax to turn off a debugging option?

set +option

what is the syntax to turn on a debugging option?

set -option

what does the Xdefaults file do?

set default look and feel on a system wide basis

what does the .Xresources file do?

sets the default look and feel on a user level basis

what are the different options to quote?

single escape (\), strong quoting ('), weak quoting (")

what does continue in loop control do?

skips to the next value/iteration if it exists

what is the command to turn on SSH tunneling for XWin?

ssh -X remote host

what is the command to turn off SSh tunneling for XWin?

ssh -x remote host

what are the two types of loops?

standard and three expression loops

\t sequence

tab

what does startx/xstart do?

temporatily places the machine in X mode

who is the x-client?

the GUI applications themselves

what happens at login time for XWin?

the Xdefaults and .Xresources files get merged

what is a XWin host?

the computer

what does the x in the DISPLAY XWin variable mean?

the display number

what must be set before a shell script can be run?

the executable bit

modifers

the rnage of test the REGEX is to match

what does the y in the DISPLAY XWin variable mean?

the screen number

what can happen if an error is encountered?

the script will error out or will behave improperly

what happens if a ? glob does not match anything?

the shell assumes that the filename contained a '?' character, and if it doesn't find it, it will return a "no such file" error

what is command substitution

the shell performs the commands and then the output can be stored to a variable

what will happen if a REGEX is not quoted when being sent as an argument for an external command?

the shell will interpret it first instead of the command

who is the x-server?

the software that is located on the user machine

What is X Windows?

the standard graphical engine for UNIX and Linux

what must be used to create a scalar variable that contains a space?

the string needs to have quotes

what is the advantage of double bracket testing over basic testing?

the syntax of double bracket it more akin to normal programming while still supporting the single bracket key words

what happens if an invalid selection is made in a select loop?

the variable is not set and the choices are represented again, code block is NOT executed

when is recursion useful?

to break up work into small pieces and then building it back up

what is stored in the DISPLAY XWin environment variable?

to place to display its output

what is the best practice when parsing an array created by ls command?

to quote filenames

T/F a computer can be both the x server and x client

true

T/F a display can have multiple screens

true

T/F a if/elif statement can NOT have a else clause at the end

true

T/F arrays cannot use negative numbers as an index

true

T/F debugging options can be turned on for small portions of the script

true

T/F double parenthesis syntax supports C style ternary operations

true

T/F globbing can be used in case statement patterns

true

T/F read-only can be used for both scalar and array variables

true

T/F scalar variables can be turned into an array without losing the original value?

true

T/F the else in a if/elif/else is paired with the elif, not the if

true

T/F the select loop runs in an infinite loop

true

T/F the shell can perform simple integer math

true

T/F there is no typing of variables in a shell script

true

T/F when setting multiple array values in an existing array, the indices do not need to be in order

true

T/F you can use multiple ? in a row when globbing

true

T/F you can you ++ and -- to increment/decrement a value with double parenthesis syntax

true

T/F quotes can be used anywhere

true, as long as all the meta characters are within the quotes

T/F ls chapter*doc will return chapterdoc

true; it matches zero or more characters

T/F desktop environment is not the same thing as a window manager

true; it runs on top of the window manager

what is the syntax to define a function variable as a local variable?

typeset VAR=val

what is the syntax to delete a variable?

unset VAR

what is the syntax for an until loop?

until CONDITION; do CODE done

what is the syntax for a one line until loop?

until CONDITION; do CODE; done

what are ways to break up long lines of code?

use a "/" or single/double quotes

grep -E

use extended regular expressions

how are multiple embedded spaces preserved in a string?

use of quoting

what is the best way to debug a new/unknown script?

use the first line of script method with the -xv flags

what is a quick way to enable debugging in a script?

use/enable debugging hook function via environment variable

what happens when the last process started in .xsession terminates?

user is logged out

what does the .xsession file do?

user level customization and runs when log onto a X11 terminal to automatically startup any XWin programs

what happens if a valid selection is made in a select loop?

variable is set, code block is run, choices are displayed again

-v debugging option

verbose mode, displays the lines as the script reads them

what is chaining?

when a function calls another function

what is recursion?

when a function calls itself

what is nesting a loop

when placing a loop in another loop

when does a while function end?

when the condition is not true or the command returns something other than 0

when does a until function end?

when the condition is true or the command returns 0

what is stderr?

where error messages are sent

what is stdout?

where output from the application is sent; value of 1

what is stdin?

where the input to the application is sourced; value of 0

what does the first line of a shell script indicate?

which shell to use for the script

what is the syntax to do a while loop

while CONDITION do CODE done

what is the syntax for a one line while loop?

while CONDITION; do CODE; done

how do you send a REGEX as an argument for an external command?

wrap the REGEX in single quotes

what is the solution when you want to enter a string in a command that uses spaces as parameter delimiters?

wrap the string in quotes or escape the spaces

what daemon automatically launches the X Win

xdm

what is the command to show to allowed hosts?

xhost

what is the command to add a host to the allowed hosts list?

xhost +hostname

what is the command to remove a host from the allowed hosts list?

xhost -hostname

what does /x*/ match?

zero or more of the char ''x"


Kaugnay na mga set ng pag-aaral

BIOL 416 FINAL EXAM (OLD EXAM Qs)

View Set

N123 PrepU Ch.32: Assessment of Hematologic Function and Treatment Modalities

View Set

Chapter 1 (all chapters and quiz q's)

View Set

Exam 1 A&P Abdominopelvic Quads/ Regions

View Set