UNIX Scripting Review

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Comment lines start with what character?

#

What is the first line of a bash shell script started with?

#!

What metacharacter indicates the end of a line

$

What command can you use to take input from the user?

$< or read

What format option specifies a string up to 10 characters and left justified?

%-10s

To place the following command, sleep 30, in the background what character is used?

&

What character specified in the replacement string will copy what was found?

&

What odd punctuation mark do you use for command substitution?

' '

default field separator

'blank' or whitespace

awk

-UNIX programming language used for manipulating data and generating reports -data can come from stdin or from one or more files -command line or embedded in other shells -scans files line by line to match patterns and, if requested, perform actions

fields

-a line is broken into fields, numbered starting at $1 -can be up to 100 fields

the Print Function

-action in awk has to be enclosed in curly braces -to print fields 1 and 5 in the action statement: {print $1, $5} -the comma after the field tells the print statement to insert whitespace between the fields

Structure of Records and Fields

-awk does not see input data as a string of characters but actually applies a format or structure to the input -it does this with an implied field separator(default: whitespace) and line separator (default: newline) -these are stored in awk variables ORS, RS and within specific limits these values can be modified -field separator can be specified on command line with -F option

awk Programming Model

-awk views input stream as collection of records that can be divided into fields -a record is normally a line -definitions of records can be modified, even during processing -awk uses patters and actions to act on records and fields -multiple input files can be acommodated

Actions

-enclosed with curly braces {} -simple actions include {print } -conditional expressions, if/else/ can be performed -arithmetic operations can be performed on fields

What argument specifies the key field to sort on with the sort command?

-k

adding to output

-output can be formatted -using the print function text can be added to the output of a field -prints 'Store ID#:', a tab, then the contents of field 1: {print "Store ID #:\t" $1}

Patterns

-typical pattern matching familiar from grep and sed are available -matching on any field in a record can be done -match operator ~ is available for finding a match on a specific field -POSIX character classes can also be used

What argument will only return unique occurrences of a record with the sort command?

-u

If the current directory is not part of your search path (which it should not be for security reasons) how would you execute a command called mine in your current directory?

./mine

The default regular expression delimiter in sed is what?

/

What character indicates a directory boundary?

/

What exit status is reserved for successful execution of a command?

0

ASCII occupies what code range in UTF-8?

0-127

Pocesses are run at startup - the first process, systemd or init, has what process ID?

1

There are four basic system calls, what are they?

1. fork 2. wait 3. exec 4. exit

Two loop types are mentioned. Name them.

1. while 2. for

There are multiple prompts, a primary, a secondary, and sometimes a tertiary. The primary prompt often has a $ sign as its last element. The secondary prompt usually consists of one character. It is most often one of following. Which is it?

>

What language was the /bin/sh based on?

Algol

Thompson and Ritchie worked for what company?

Bell Laboratories

What statement will match a condition then move onto the next item?

Continue

Which of the following items will this ls command match?: ls D*

Documents, Dorothy, Doris

Once awk has read each record, you can use what awk tool to provide output of the array?

END

Which of the following are features of shell scripts?

Ease of development, Portability, Simplicity

What variable represents the number of records (lines) in a file?

FNR

What represents the input field separator variable?

FS

A function creates a child process.

False

A value for a variable cannot be supplied from the command line.

False

Bash will do floating point math without any problems.

False

By default the sed command will overwrite the existing file

False

More than one index of the same value can exist in an array.

False

UNIX/Linux is not case sensitive

False

User defined variables must be declared.

False

What variable is used to ignore case?

IGNORECASE

Who developed the grep tool?

Ken Thompson

Linux was initially created by what person?

Linus Torvalds

Which of the following is not a Linux variant: CentOS, Mint, MVS or Ubuntu?

MVS

UNIX was developed after experience with what other operating system?

Multics

What variable represents the number of fields on a record?

NF

What variable represents the record (line) number?

NR

Arrays in the bash shell have how many dimensions?

One

In the following example what is the variable name? read TEST

TEST

Command completion can be used to complete a partially typed command. What key is used to trigger command completion?

Tab

In the bash shell a set of commands can be separated by double pipes, ||. The second command will execute on what condition?

The first command fails

In the bash shell a set of commands can be separated by double ampersands, &&. The second command will execute on what condition?

The first command is successful

ASCII is a sub-set of UTF-8?

True

POSIX stands for Portable Operating System Interface

True

Range patterns, like those used in sed, can be used in awk.

True

Sed processes a file a line at a time.

True

The -a option on read will read an array.

True

The percent sign, %, is used to tell printf that you are specifying a format.

True

User defined variables cannot begin with a number.

True

You can redirect output in awk.

True

What character is used as the escape character?

\

To find all aliases you have which option to the alias command would you use?

alias -p

The string in an array is used as what?

an index

takes in a line and places it in a buffer, $0

awk '{print $1}' employees / awk '{print $0}' employees

Two tools for handling math in shells are which of the following?

awk, bc

What statement is used to get out of a loop when a condition is met?

break

What command is used to change permissions on a file?

chmod

The Korn shell (ksh) and bash shell use pieces from at least two other shells. The two mentioned in the online lecture are?

csh and sh

What would you type to source a .profile file in the current directory?

dot

When positional parameters are set they can be displayed using echo. If the following set of positional parameters is created: set Tom Dick Harry, what echo command would be needed to produce the output of Dick Harry Tom?

echo $2 $3 $1

What command can you type to display your search path?

echo $PATH

Which of the following may be used for text display in shell scripts?

echo, print, printf

If you want to search for Wood or Fiberglass using egrep what would the regular expression be?

egrep '(\<Wood\>|\<Fiberglass\>)+'

An associative array is a table of values which are called what?

elements

What command can be used to turn on or off builtin commands?

enable

What does the command 'g' does what in sed?

everything that matches the command in the line will be substituted

What permission needs to be enabled for user, group, or other before a shell script can be run?

execute

What permission needs to set in order to run a shell script?

execute

What command do you use to make sure your variable is global?

export

A history of commands can be accessed and resubmitted using the history command or another command. That command is?

fc -l

To search for home or Home with grep you can use what syntax?

grep '[Hh]ome'

What command can you use that shows frequently used commands?

hash

What value represents incrementing the variable i after, not before, processing a field?

i++

What is the -n option used for?

it does not print the lines of buffer to stdout

What command can be used to view running jobs?

jobs

The &&, ||, and ! are what type of test?

logical

What option is used to tell sed to substitute?

s

How would you restrict the ouptut of the sed command to exclude from line 4 to the end of the file?

sed '4,$d' file_name

There are commands that let you set shell options. Which two of the following are shell option commands?

shopt, set

Where does sed send its output by default?

stdout

Is the following variable defined as a string or a number: A="37"?

string

What UNIX layer sits between the hardware and the user shell?

the Kernel

In the following example the field, $6, inside square brackets is the index. The text in front of the square brackets is what? Var[$6]

the arrayname

What does the 1 in the following command represent? sed -n 's/\(Mar\)got/\1ianne/p' datafile

the buffer to which 'Mar" will be matched to if 'Margot' is found. So Margot will be changed to Marianne

Why is quoting used?

to protect special metacharacters from interpretation and prevent parameter expansion

To see whether a command is an alias, builtin, or regular executable you can use which command?

type

What single character is used to pipe the output of one command into another command?

|


संबंधित स्टडी सेट्स

Word Choice and Evidence in Wheels of Change, Part 3

View Set

MAR 5625 - Marketing Research and Analytics - Chapter 3

View Set

Chapter 2: Sociological Research

View Set