Unix Chapter 7

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

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 you create a script, provide the command on the first line of the script that sets the particular shell to use the Bash shell.

#!/bin/bash

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 variable settings, aliases, and other settings that you always want in effect when you are in the Bash shell.

.bash_profile

The ________ file serves an additional purpose that is not shared by the .bash_profile (or .profile) file - it is run each time you start a Bash shell within a Bash shell, which is called running a subshell.

.bashrc

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

When using the test command, an exit status of ___________ means "true" (i.e., the condition has been met).

0

Who sets up the default shell for a particular user account? 1. System administrator 2. User or system administrator 3. Group administrator 4. Operating system 5. User

1

You are trying to create a new function to perform a listing of hidden files. The code that you have written does not work. Check the following code and find the error or errors. Choose all that apply) listhidden[] { ls -H } 1. Replace ls -H with ls -a 2. You must use a semicolon after ls -H 3. Replace the square brackets after listhidden with open and closed parentheses. 4. Replace the curly brackets on lines 2 and 4 with open and closed parentheses.

1,3

Which of the following are login scripts that you might find used in a UNIX/Linux system? (Choose all that apply) 1. .bash_profile 2. .loginbash 3. .bashrc 4. .profile

1,3,4

Using the test command implement the following programming logic: If the variable today is equal to "Friday" display the message "TGIF!".

1. if test $today = "Friday" 2. then 3. echo "TGIF!" 4. fi

To instruct the system to run a script with a specific shell, the first line of the script must start with the __________ character. 1. ! 2. # 3. : 4. - 5. $

2

Which of the following integer testing options of the test command represents greater than? 1. -ne 2. -gt 3. -> 4. -ge 5. ->>

2

You have a script that needs to ensure that a file is not a character special file before you work on that file. Which of the following commands enables you to evaluate this type of file? 1. None of these choices 2. test -c 3. != char 4. filetest 5. chmod a+w

2

You have entered CLR=`clear` at the command line and then entered export CLR. Which of the following commands can you now enter to clear the screen? 1. "clear" 2. echo $CLR 3. None of these choices 4. ~CLR 5. CLR

2

You have written a set of functions that are stored in the .funcs file. How can you use the functions in this file in scripts that you write? (Choose all that apply) 1. By calling this file .funcs, the functions in the file are automatically available whenever you log in. 2. Modify your login script, so the login script loads the .funcs functions into memory. 3. Use the callscripts .func command in your scripts. 4. Modify your scripts so that they load .funcs into memory.

2, 4

Which of the following scripts run automatically when you log in to your account? 1. .login 2. .bashrc 3. .bash_profile 4. .user 5. .custom

3

You are using the test command to determine if the value in $amount is equal to 1000 and the result is 0. What does this mean? 1. Modify your login script, so the login script load the .funcs functions into memory. 2. You are trying to divide by zero, which is not allowed. 3. The 0 means true; the value in $amount is equal to 1000 4. None of these choices 5. $amount is empty

3

You have created a shell script containing functions and named it .functions. When you type . .functions and press enter, what does this do? 1. It runs all of the functions in the script 2. It starts the Emacs editor to further edit the .functions script. 3. It loads the functions in memory. 4. It runs a preliminary test of the function in the script. 5. None of these choices.

3

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? (Choose all that apply) 1. Teach him to type shell$=bash each time he logs in. 2. Install the Bash shell in his home directory. 3. Have a system administrator change the /etc/passwd file to use the Bash shell for that account. 4. Have the user edit the .group file in his home directory to have the line !Bash

4

Which of the following commands is used to view hidden files? 1. ls -f 2. ls-l 3. ls -c 4. ls -a 5. ls

4

Which of the following commands takes the contents of an input file, applies actions to the contents of the file as specified in the commands arguments, and sends its output to standard output? 1. vi command 2. grep command 3. bash command 4. sed command 5. bin command

4

$4 is an example of a(n)__________________________. 1. Currency format designator for the grep command. 2. None of these choices 3. test result 4. integer format used with the sed command. 5. positional variable

5

After you enter test $fname = "Jenna" at the command line, which of the following commands can you use to find out the result? 1. print test 2. None of these choices 3. test \results 4. !test 5. echo $?

5

The test command can be used to do all of the following options EXCEPT _________. 1. Perform Boolean tests and delete strings. 2. Determine if a file exists and what type of file it is. 3. Perform Boolean tests. 4. Test strings. 5. Delete Strings.

5

Which of the following lines would you use to determine if the variable result contains a value larger than 244? 1. $result grep 244 2. echo result > 244 3. None of these choices 4. test result !lt; 244 5. test $result -gt 244

5

Which of the following scripts runs when you start a subshell in Bash? 1. .bash 2. .bashss 3. .bash_profile 4. .bashcfg 5. .bashrc

5

Which of the following test command options test for the existence of a file? 1. -d 2. -X 3. -s 4. -f 5. -e

5

Blank # 1) Create a shell varriable named CURMONTH that outputs the calendar for the current month, and Blank # 2) make it an environment variable.

Blank # 1) CURMONTH=`cal` Blank # 2) export CURMONTH

Perform the following steps: Blank # 1) Append the directory $HOME/source to your current path, and Blank # 2) Display your current path to ensure that it was added

Blank # 1) PATH=$PATH:$HOME/source Blank # 2) echo $PATH

Perform the following steps: Blank # 1) Set the variable value equal to 51; Blank # 2) Determine if the variable number is less than the variable value; Blank # 3) Display the exit status of the most recent command executed.

Blank # 1) let value=51 Blank # 2) test $number -lt $value Blank # 3) echo $?

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

Blank # 1) whoisthere() Blank # 2) { Blank # 3) who -H Blank # 4) }

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

Blank # 1: test -d source Blank # 2: echo $?

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

CLEAR=`clear`

In Linux, all user accounts typically have a default datenow() shell function in the login script. True or False

False

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

False

The script code line, if test "endloop" = "q" is incorrect because the statements after if must be in curly brackets. True or False

False

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

False

To get the value of the second argument of a shell function from inside the function, would you use the notation %2? Yes or No

No

Append the directory $HOME/source to your current path (i.e., the PATH variable).

PATH=$PATH:$HOME/source

___________ contains statements that are similar to actual programming statements.

Pseudocode

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 or False

True

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

True

The test command returns a value known as the exit status. True or False

True

Can you define functions from the command line? Yes or No

Yes

Does the test command with the -a option indicate a logical AND? Yes or No

Yes

Is a Boolean operator used to determine the truth value of an expression? Yes or No

Yes

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

echo $?

Use the echo command to verify the contents of the variable that identifies which shell you are using (e.g., the Bash shell).

echo $SHELL

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

grep 605-256-5165 phonebook

Use the grep command to retrieve a record from the phonebook file that matches the phone number 605-256-5165, and then pipe the output to the tr command to replace the colon characters in the record with space characters.

grep 605-256-5165 phonebook | tr ':' ' '

Modify the following programming logic to use the test command: if [ "$veg_name" = "carrots" ]

if test "$veg_name" = "carrots"

Create a variable called mem_size and set its contents to 1024.

mem_size=1024

Create the variable myvar with the value 50.

myvar=50

Two popular and proven analysis tools for designing programs that were discussed in the test are to create flowcharts and to write__________________.

pseudocode

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

test ! -d source

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

test ! -f data

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

test ! -r data

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 lname is equal the "Smith".

test $lname = "Smith"

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

test -e data

Use the test command to determine if the file data is writeable (i.e., may be modified).

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 (i.e., empty).

test -z $lname

Create the variable value with the value 51.

value=51


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

MKT 350 Test 3, MKTG 351 CHAPTER 15, MKT 230 Chapter 14, QUIZ Chapters 11, 14,15,, MKTG 330: Chapter 14 Quiz, MKTG 409 Chapter 14

View Set

AAMC Practice Test 3 - C/P Review

View Set

Microbiology Final Questions - The Quizzes

View Set

Chapter 13-Env Science; multiple choice

View Set

PrepU - #1 Oxygenation and Perfusion

View Set