Linux Command Line
1 - Hello Bash Scripting
What this command does is shows all the available shells on system. Any can be used.
Shows path of bash. Add this to any script that is written
In order to make script executable, have to add chmod +x to it.
./ in front to run script
2 - Redirect to file
Show how to capture output and then send it to a file.
When ran, creates a file called file.txt
Script becomes an editor. Whatever is written when script is executed
In order to come out of it, you have to press Ctrl + D.
Output of one displays output of another. Essentially replaces text.
In order to append, put 2 >>
3 - comments
Has no value except explaining code to programmer.
Doesn't show in execution of code. If there are 500 lines of code it does not make to out # on each individual line
:'
' to multi line comment
Heredoc delimeter
Similar to the variable like
4 - Conditional statements
Inside if condition, checks that count equals 10. Since condition is true, execute the block.
No output, since no else block and program doesn’t know what to do.
AND Operator
Checks if age is greater than 18 and less than 40
Both conditions have to be true
One true condition, one false condition
-o for OR operator . -o can also be substituted with ||
5 - Loops
While:
For:
6 - Script Input
Input represents $1, $2, $3
Create an array with unknown number of inputs
Prints all the values that are taken in.
Prints length of array as well
6 Script Input
7 Script Output
1 file for standard output and 1 file for standard error
8 Sending Output
Output from one script is being sent to another
9 Strings Processing
Compares 2 inputs to see if they match
10 Numbers and Arithmetic
To add numbers:
Or can use expression
11 Declare Command
Bash does not have a strong type system. Cannot restrict variables, however you can use attributes set by a command. Declare is a bash built in command that allows you to update attributes applied to variables within scope of shell.
Declare -p shows ALL variables
Can see that it is trying to print out twice. This is because pwd file is being declared as a read variable
12 Arrays
Prints out all of the arrays
13 Functions
In order to make functions work, they need to be called
14 Files and Directories
Learn how to create directories/check if current directories exist or not, how to append text from file and how to read line by line
Creating a filename
15 Curl in scripts
16 Professional menus
Select loops and how to work with it
Needs a check statement.
17 Wait for filesystem events with inotify
Inotify is a linux kernel subsystem that acts to extend file systems. Whatever changes are made inotify will monitor the files and directories
18 Introduction to grep
19 Introduction to awk
Awk - scripting language used to manipulate data and generate reports
20 Introduction to sed
Sed stands for stream editor and can be used to manipulate text files
21 - Debugging Bash Scripts
Bash offers an extensive debugging facility so you know if it doesn’t go according to plan. The error includes the line and where the error is
Bash -x shows you the code that is being executed.