Linux certification-chapter7(study notes)

in #learn2 years ago

linux.PNG

linux ch7.PNG

Command Input and Output

• Divided into 3, standard input, standard output, standard error

Redirection

• Symbol “>”, use 0, 1 and 2 for file description, see figure 7-1
• &> redirects both 1 and 2
• To add data use 2 “>>”
• Use tr command to replace characters

Pipes

• Refer to table 7-1 and figure 7-2 for commands
• “|” for multiple commands.
• Filter commands take stdin and transform it into stdout See table 7-2

Shell Variables

• There are several reserved variables stored in memory.
Environment variables
• Set command, to see all variables and their set values
• Use the history command to see last commands used
• View table 7-3

User-defined variables

• You can create you own variables do not start them off with a number use a capitalized convention.
• Use the export command to run variables in the subshell
• Use env command to display variables

Other variables

• Not displayed with set or env.
• UMASK variable.
• Use the alias command to create a shortcut for a command

Environment files

• Place variables in a file to be executed with startup/login.
• Other variables not saved are lost

Shell scripts

• Files with executable commands in them are shell scripts
• Any command in BASH shell can be placed in a script
• First line (hashpling) specifies the pathname to the shell that interprets the shell script

Escape Sequences

• Used to manipulate text displayed in the terminal. See table 7-4 for more commands

Reading Standard input

• Get input from a user using the read command and place it in a variable

Decision constructs

• Alter the flow of a program based on logical checks or completion of tasks.
• If construct, check if something happened.
• See table 7-5 and 7-6
• Case construct, same as the if but with more options and paths
• && and || constructs, and, and or

Loop constructs

• The for construct, loops between do and then done
• The while construct, loops through the test statement, if test fails it is done.
• The until construct, is opposite to the while construct.

Special variables

• Shell expansion variables, $ with the command, substitution
• Positional parameters, are arguments withing a shell script
• Built-in-variables, see table 7-7

Functions

• Used for recalling and executing a set of commands
• Scripts that contain multiple functions only (function calls) is a function library

Version control using git

• Helps keep track of the changes that you made to files, can add commentary to the changes that is made. Can revert to previous changes.
• You will need to configure git to work on the server. See table 7-8 for common git commands.

Chapter Summary

Credit: see image for resource credit

•  Three components are available to commands: Standard Input (stdin), Standard Output (stdout), and Standard Error (stderr). Not all commands use every component.
•  Standard Input is typically user input taken from the keyboard, whereas Standard Output and Standard Error are sent to the terminal screen by default.
•  You can redirect the Standard Output and Standard Error of a command to a file using redirection symbols. Similarly, you can use redirection symbols to redirect a file to the Standard Input of a command.
•  To redirect the Standard Output from one command to the Standard Input of another, you must use the pipe symbol (|).
•  Most variables available to the BASH shell are environment variables that are loaded into memory after login from environment files.
•  You can create your own variables in the BASH shell and export them to programs started by the shell. These variables can also be placed in environment files, so that they are loaded into memory on every shell login.
•  The UMASK variable and command aliases are special variables that must be set using a certain command. •  Shell scripts can be used to execute several Linux commands.
•  Decision constructs can be used within shell scripts to execute certain Linux commands based on user input or the results of a certain command.
•  Loop constructs can be used within shell scripts to execute a series of commands repetitively.
•  Special variables can be used within shell scripts to access built-in shell information, access positional parameters, and to expand commands and variables.
•  Functions can be created within a shell script to store commands and constructs for later execution. Function libraries are shell scripts that only contain functions; they can be run at the beginning of other shell scripts to provide a rich set of functions.
•  Git can be used to provide version control for files on your system that are modified over time, including shell scripts. These files are stored as a master branch within a Git repository that can be cloned to other computers for collaboration. Git users can create additional branches to test file modifications before merging them into the master branch.
•  After changes are made to files within a Git repo, they are normally staged and added to a commit that provides a snapshot of the files at that time. You can revert files to a previous state by referencing the associated commit.