Chapter 7 Study Guide
Command input and output
Bash Shell Responsible for providing user interface
Interprets commands entered on command line
Can manipulate command input and output
Input and Outputs of commands Represented by labels know as file descriptors. There are 3 file descriptors:
Standard input (stdin) information processed by the command during execution
Standard output (stdout) refers to the normal output of a command
Standard error (stderr) refers to any error messages generated by the command
Both stdout and stderr are displayed on the terminal screen by default
Use the BASH shell to redirect stdout and stderr from the terminal screen to a file on filesystem
Use the > shell metacharacter followed by absolute or relative pathname of the file
ls /etc/hosts /etc/h 1>goodoutput
Use the < to redirect a file to the stdin
cat </etc/issue
Redirection only occurs between a command and a file. However you can send stdout of 1 command to another command as stdin. You can do this by using the pipe shell metacharacter "|" This symbol can be created by pressing the shift key along with the \ key. Common use for piping is to reduce the amount of information displayed.
Shell variables
A BASH shell has several variables in memory at one time. A variable is a reserved portion of memory containing info that might be accessed. Most variables in the shell are referred to as environmental variables because they are typically set by the system and contain info that the system and programs access regularly. Users can also create custom variables. Special variables can also be used for executing commands and creating new files and directories.
Environmental Variables Many are set by default in the BASH shell. To see a list of these variables and their values use the set command. Other variables used to set the user’s work environment:
PS1 – The default shell prompt
HOME – The absolute pathname to the user’s home directory
PWD – The present working directory in the directory tree
PATH – A list of directories to search for executable programs
Home Variable Used by programs that require pathname to the current user’s home directory. If root user logs in, the HOME variable is set to /root. If user logs in, the HOME variable is set to /home/user.
SHOULD NOT BE CHANGED!
PWD Variable PWD stores the current user’s location in the directory tree. It is affected by the cd command and used by other commands, such as pwd, when the current directory need to be identified.
SHOULD NOT BE CHANGED!
Path Variable One of the most important variables in the BASH shell. It allows users to execute commands by typing the command name alone. If the executable file is in a directory not listed in the PATH variable (such as the /root directory)the user must specify either the absolute or relative pathname to the executable file.
User Defined Variables To create a variable, specify the name of the variable followed by = and the new contents. Variable identifies can contain alphanumeric characters, the "–" character, or the "_" character. They must not start with a number. They are typically capitalized to follow convention (HOME, PATH, etc.). To create a variable called MYVAR with the contents “This is a sample variable” you would use these command:
MYVAR="This is a sample variable"