UNIX Chapter 7

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

Which of the following Boolean operators for the test command represents logical negation?

!

To instruct the system to run a script with a specific shell, the first line of the script must start with the __ character.

#

Assume that you are creating a script. Enter a line in that script to ensure that the script uses the Bash shell.

#!/bin/bash

When the first line in a script starts with ____, the Bash shell will be used to interpret that script.

#!/bin/bash

Provide the line that you would add to your .bashrc file to load the .myfuncs script from the source subdirectory of your home directory.

. ~/source/.myfuncs

The ___ file is run each time you log in or give the command to set Bash as your current shell (some Linux systems, such as SUSE Linux call this the .profile file, instead). It typically contains settings, such as environment variables settings, aliases, and other settings that you always want in effect when you are in the Bash shell.

.bash_profile

Which of the following scripts runs automatically when you log in to your account?

.bash_profile

Which of the following scripts runs when you start a subshell in Bash?

.bashrc

If you prefer using the vi editor, you have the option of configuring a file called ____ in your home directory.

.exrc

Which file is used to initialize the environment for the vi editor?

.exrc

Set your shell from the command line to the bash shell

/bin/bash

The ___ file holds the configuration information that establishes a default shell for a user account.

/etc/passwd

When using the test command, an exit status of ___ means false.

1

One of the users in your company has an account that always starts in the Korn shell as the default, but your company has supplied him with scripts designed to run using the bash shell. What is the best approach to ensure that his account starts in the Bash shell?

Have the system administrator change the /etc/passwd file to use the bash shell for that account.

A program should always check its input to ensure that the user has entered acceptable information. This is commonly referred to as which of the following?

Input Validation

Use the test command, implement the following programming logic: While the variable guess is not equal to "correct", display the message "incorrect!".

while test $guess != "correct" do echo "incorrect!" done

Create a function called whoisthere that displays a listing of who is logged in and displays the column headings for the information displayed.

whoisthere() { who -H }

Which of the following operators can you use to make the tr command work as a filter for input from another command's output.

|

Use the echo command to verify the contents of the variable that identifies which shell you are using.

echo $SHELL

True or False. A shell function can typically accept up to 7 positional parameters

False

True or False. A(n) diamond is a symbol in a program flowchart that represents a process that is to occur.

False

True or False. Does the test command with the option -d verify the existence of a regular file?

False

True or False. Instructions that are similar to actual programming statements are referred to as flowcharts.

False

True or False. The ls -a command does not list hidden files.

False

True or False. The test command cannot be used to evaluate a file's permissions, but the sed command can be used for this purpose.

False

True or False. To get the value of the 2nd argument of a shell function from inside the function, would you use the notation %2?

False

True or False. When using the test command, an exit status of one indicates that the test results is true.

False

Set the shell variable, CLEAR, to the output of the clear command.

CLEAR=`clear`

You are writing a series of 10 scripts in which you often use the same code to relocate the cursor in the same position on the screen. What is a method you can use to save time in programming?

Create a shell function

A new programmer often uses the vi editor to create scripts and often has a need to view lines as numbered in the vi editor. What advice do you provide?

Create the .exrc file in the programmer's home directory to contain the line set number

As system administrator, you have several default aliases that all users must have set up for them to use automatically from their user accounts on your company's Linux server. Which of the following is the easiest way for you to ensure all users have access to these default aliases?

Create the aliases in the /etc/.bashrc or /etc/bashrc file

You have created a shell script containing functions and named it .functions. When you type . .functions and press enter, what does this do?

It loads the functions into memory

Append the directory $HOME/source to your current path

PATH=$PATH:$HOME/source

True or False. .bash_logout is a file that performs default logout functions for an account.

True

True or False. A(n) flowchart is a logic diagram that uses a set of standard symbols to explain a program's sequence.

True

True or False. An oval in a flowchart is also referred to as as terminator, it indicates the beginning and/or end of a program.

True

True or False. By using a pipe operator (|), the translate utility works as a filter in cases where the input comes from the output of another UNIX/Linux command

True

True or False. Does the test command with the -a option indicate a logical AND?

True

True or False. Is a Boolean operator used to determine the truth value of an expression?

True

True or False. The exit status of a test is normally detected in the script by a(n) if statement or a looping statement

True

True or False. You can define functions from the command line?

True

You are creating a script and want to test to see if two expressions are both true. What should you use for the test?

Use a boolean operator with the test command

You have written a script that requires using the /data directory. How can you ensure that the /data directory already exists in order to fully use the script you have written?

Use the command test -d /data early in the script

Use the cat command to display the contents of the phonebook file, and then pipe the output to the tr command to change lowercase characters to uppercase.

cat phonebook | tr '[a-z]' '[A-Z]'

The output of which of the following commands is a sequence of values that erases the contents of the screen

clear

Declare the simple datenow function to display today's date using the date command.

datenow() { Date }

The test command can be used to do all of the following options except ___.

delete strings

After you enter test $fname = "Jenna" at the command line, which of the following commands can you use to find the result?

echo $?

How can you view the exit status of the test command directly from the command line?

echo $?

Use the echo command to display the exit status of the most recent command executed.

echo $?

you have entered CLR=`clear` at the command line and entered export CLR. Which of the following commands can you now enter to clear the screen.

echo $CLR

Use the grep command to search the file phonebook for the number 605-256-5165

grep 605-256-5165 phonebook

Which of the following does the same thing as the script line: if["$R_Value" = "40" ]?

if test "$R_Value" = "40"

Create a variable value with the value 51.

let value=51

Set the variable lname equal to "Smith"

lname="Smith"

Which of the following commands is used to view hidden files?

ls -a

$4 is an example of a(n) ____.

positional variable

Which of the following commands takes the contents of an input file, applies actions to the contents of the file as specified in the command's arguments, and sends its output to standard output?

sed command

Who sets up the default shell for a particular user account?

system administrator

Use the test command to determine if the directory source does not exist

test ! -d source

Use the test command to determine if the file data does not exist.

test ! -e data

Use the test command to determine if the file data is not readable.

test ! -r data

Use the test command to determine if the file smurf.c is not executable.

test ! -x smurf.c

Use the test command to evaluate whether the shell variable contains a reference to the bash shell.

test $SHELL = "/bin/bash"

Use the test command to determine if the variable lname is not equal to "Jones"

test $lname != "Jones"

Use the test command to determine if the variable myvar is equal to 50

test $myvar -eq 50

Which of the following lines would you use to determine if the variable result contains a value greater than 244?

test $result -gt 244

Use the test command to determine if the directory source exists

test -d source

Perform the following steps: 1)Determine if the file source exists and is a directory, and 2) Display the exit status of the most recent command executed.

test -d source echo $?

Use the test command to determine if the file data exists.

test -e data

Use the test command to determine if the file data exists and is a regular file.

test -f data

Use the test command to determine if the file data is readable.

test -r data

Use the test command to determine if the file smurf.c is readable and executable.

test -r smurf.c -o -x smurf.c

Use the test command to determine if the file data is writable.

test -w data

Use the test command to determine if the file smurf.c is executable

test -x smurf.c

Use the test command to determine if the variable lname is zero in length

test -z $lname

Perform the following steps: Blank #1) Determine if the variable lname is zero in length. Blank #2) Display the exit status of the most recent command executed.

test -z $lname echo $?

While creating a script, you want to include a way to determine if a particular string has a zero length (no contents). Which of the following commands can you use?

test command with the -z option

Use the ____ command to change standard input, such as changing uppercase letters to all lowercase.

tr


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

PTA 101: Biomechanics and Vitals

View Set

Social Media Marketing Chapter Quiz 8-11 Study Guide

View Set

Week 4 Chapter 9 Equine Clinical procedures

View Set

Exam 2 LDR alternative questions

View Set

Presentation: PHP and MySQL: Chapter 12 Cookies and Sessions [Slides 1-19]

View Set