- Home
- Server Administration
- LPIC-1 Linux Administrator 102
66.
What file might a user modify to alter his or her own bash environment?
- A.~/.startup
- B./etc/bashrc
- C./home/.bashrc
- D./home/profilerc
- E.~/.bashrc
- Answer & Explanation
- Report
Answer : [E]
Explanation :
Explanation :
The ~/.bashrc file is a non-login bash startup script file. As such, it can be used to alter a user’s bash environment, and option E is correct. There is no standard ~/.startup file for bash, so option A is incorrect. The /etc/bashrc file is a global bash startup script. Editing it will modify users’ bash environments, but an individual user should not be able to modify it, so option B is incorrect. There is no standard /home/.bashrc file; this option would be correct only if the user’s home directory were set to /home, which would almost certainly be an error. Thus, option C is incorrect. Likewise, option D’s /home/profilerc doesn’t refer to a user’s configuration file; and even if it did, profilerc isn’t a valid bash configuration filename (although ~/.profile is a valid user configuration file and /etc/profile is a valid global configuration file). |
67.
What commands might you use (along with appropriate options) to learn the value of a specific
environment variable? (Select two.)
- A.env
- B.DISPLAY
- C.export
- D.echo
- E.cat
- Answer & Explanation
- Report
Answer : [A, D]
Explanation :
Explanation :
The env command displays all defined environment variables, so option A satisfies the question. (In practice, you might pipe the results through grep to find the value of a specific environment variable.) The echo command, when passed the name of a specific environment variable, displays its current value, so option D is also correct. DISPLAY is an environment variable, but it’s not a command for displaying environment variables, so option B is incorrect. You can use the export command to create an environment variable but not to display the current settings for one, so option C is incorrect. Option E’s cat command concatenates files or displays the contents of a file to the screen, but it doesn’t display environment variables. |
68.
After using a text editor to create a shell script, what step should you take before trying to
use the script?
- A.Set the SUID bit using chmod.
- B.Copy the script to the /usr/bin/scripts directory.
- C.Compile the script by typing bash scriptname, where scriptname is the script’s name.
- D.Run a virus checker on the script to be sure it contains no viruses.
- E.Set one or more executable bits using chmod.
- Answer & Explanation
- Report
Answer : [E]
Explanation :
Explanation :
Scripts, like binary programs, normally have at least one executable bit set, although they can be run in certain ways without this feature. Thus, you should use chmod, as in option E. You should not, however, use chmod to set the set-user-ID (SUID) bit, as in option A, since this would be a security risk for most scripts. There is no standard /usr/bin/ scripts directory, and scripts can reside in any directory, so option B is incorrect. Scripts are interpreted programs, which means they don’t need to be compiled, making option C incorrect. (Typing bash scriptname will run the script, though.) Viruses are extremely rare in Linux, and because you just created the script, the only ways it could possibly contain a virus would be if your system was already infected or if you wrote it as a virus. Thus, option D is incorrect. |
69.
Describe the effect of the following short script, cp1, if it’s called as cp1 big.c big.cc:
#!/bin/bash
cp $2 $1
#!/bin/bash
cp $2 $1
- A.It has the same effect as the cp command—copying the contents of big.c to big.cc.
- B.It compiles the C program big.c and calls the result big.cc.
- C.It copies the contents of big.cc to big.c, eliminating the old big.c.
- D.It converts the C program big.c into a C++ program called big.cc.
- E.It interprets the big.c and big.cc files as bash scripts.
- Answer & Explanation
- Report
Answer : [C]
Explanation :
Explanation :
The cp command is the only one called in the script, and that command copies files. Because the script passes the arguments ($1 and $2) to cp in reverse order, their effect is reversed—where cp copies its first argument to the second name, the cp1 script copies the second argument to the first name. Thus, option C is correct. Because the order of arguments to cp is reversed, option A is incorrect. The cp command has nothing to do with compiling (option B) or converting (option D) C or C++ programs, so neither does the script. The reference to /bin/bash in the first line of the script identifies the script itself as being a bash script; it does not cause the arguments to the script to be run as bash scripts, so option E is incorrect. |
70.
What is the purpose of conditional expressions in shell scripts?
- A.They prevent scripts from executing if license conditions aren’t met.
- B.They display information about the script’s computer environment.
- C.They enable the script to take different actions in response to variable data.
- D.They enable scripts to learn in a manner reminiscent of Pavlovian conditioning.
- E.They improve code quality by improving its readability.
- Answer & Explanation
- Report
Answer : [C]
Explanation :
Explanation :
Conditional expressions enable the script to execute different sets of instructions depending on some condition, as described in option C. They have nothing to do with license conditions (option A), the computer’s environment (option B), or Pavlovian conditioning (option D). Although code readability can be influenced by proper or improper use of many programming features, including conditional expressions, this isn’t the primary purpose of conditional expressions, so option E is incorrect. |