Shell Scripting Test Review
The file descriptor stdin is represented by the number ____.
0
The file descriptor stderr is represented by the number ____.
2
You can redirect a file to the standard input of a command using the ____ metacharacter.
<
You can use the BASH shell to redirect standard output and standard error from the terminal screen to a file on the filesystem using the ____ shell metacharacter followed by the absolute or relative pathname of the file.
>
Given the syntax command -a command, the command on the left of the -a construct is executed only if the command on the right of the -a construct completed successfully.
False
To prevent a file from being cleared by the BASH shell and append output to the existing output, you can specify three > metacharacters alongside the file descriptor.
False
You are limited to using one pipe | metacharacter on the command line to pipe information from one command to another command.
False
Describe the for construct in shell scripting. How and why is it used?
For something in something For variable in a list It is used because if you give it a list it will do something
The _________________ environment variable contains a list of directories to search for executable programs.
PATH
Any command that can be executed on the command line can also be placed inside any shell script.
True
The test statement ____ would be used to determine if A is numerically greater than B.
[ A -ge B ]
The ____ escape sequence is used to suppress a carriage return
\n
Most configuration files on Linux systems are delimited using ____ characters.
colon
The ____ command could be used to view the contents of the environment variable that represents the BASH shell prompt.
echo $PS1
A case construct must be ended by __________.
esac
If you have ____ permission to a shell script, you can execute the shell script like any other executable program on the system.
read and execute
To see a list of the environment variables and their current values on a system, you can use the ____ command.
set
Most commands that are run by the shell are run in a separate ___________, which is created by the current shell.
subshell
The ____ command can be used to replace characters in a file sent via Standard Input.
tr
You can send the standard output of one command to another command as standard input using the ____ shell metacharacter.
| (pipe)
What are shell scripts? Why and how are they executed?
Shell scripts are text files containing commands and special constructs. They are typically used for file manipulations, program execution and text printing. They are executed by using the chmod 777, chmod 766, chmod 775, chmod u+x command. They are executed to run the script.
What are shell variables? What are environment and user-defined variables?
Shell variables is a variable that is available only to the current shell. An environment variable is available system wide and can be used by other applications on the system. A user-defined variable are variables which can be created by the user and exist in the session. This means that no one can access user-defined variables that have been set by another user, and when the session is closed these variables expire.
The ____ environment file is always executed immediately after login for all users on the system, and sets most environment variables, such as HOME and PATH.
/etc/profile
What is a decision construct? What is the most common type of decision construct, and what is the syntax for using it?
A special construct used in a shell script to alter the flow of the program based on the outcome of a command or contents of a variable. Common decision constructs include if, case, $$, and | The most common type is if the if statements, elif, case etc
25. Write a shell script named ExamScript to accomplish the following: Asks a user for their name and displays a "Hello" to them using their name. Displays all of the users that are logged on. Displays the path variable. Displays the current working directory. When you are done with the script tell me what else must be done to allow the script to run from the command line.
#!/bin/bash Echo -e "Please enter your name: " Read name Echo "Hello $name" W Echo $PATH Echo $PWD Chmod u+x or chmod 777, make sure it is in a directory you know