Bash - Summary of this YouTube tutorial.
Test on Ubuntu Server 20.04.3 LTS (Focal Fossa)
1-Hello Bash Scripting
Example 1: Get all the shell availability on linux server.
$ cat /etc/shells
OUTPUT
# /etc/shells: valid login shells
/bin/sh
/bin/bash
/usr/bin/bash
/bin/rbash
/usr/bin/rbash
/bin/dash
/usr/bin/dash
/usr/bin/tmux
/usr/bin/screen
/bin/sh
/bin/bash
/usr/bin/bash
/bin/rbash
/usr/bin/rbash
/bin/dash
/usr/bin/dash
/usr/bin/tmux
/usr/bin/screen
Example 2: Get current bash path
$ which bash
OUTPUT
/usr/bin/bash
Example 3: Create script
$ touch myfirstscript.py
Example 4: To see the script use "ls"
$ ls
OUTPUT
-rw-r--r-- 1 root root 0 Feb 8 10:02 myfirstscript.py
Example 5: Make it executable
$ chmod +x myfirstscript.py
OUTPUT
-rwxr-xr-x 1 roboscr roboscr 0 Feb 8 10:02 myfirstscript.py
Example 6: Write your first script, edit the script by using vi editor.
Filename: myfirstscript.py
Content on script:
#! /bin/bash
echo "Hello Friends"
$ ./myfirstscript.py
OUTPUT
Hello Friends
2-Redirect to file
Example 1: Write to file in txt.
$ echo "Hello Friends" > newfile.txt
Example 2: Write to file in txt in append mode
$ echo "Hello Friends" >> newfile.txt
3-Comments
Example 1: Single line comments
# This is my first comment
# This is my second comment
Example 2: Multi line comments
: '
This is my first comment
This is my second comment
This is my third comment'
4-Conditional Statements
5-Loops
6-Script input
7-Script output
8-how to send output from one script to another scrpt
9-String Processing
10-Numbers and Arithmetic
11-Declare Command
12-Arrays
13-Functions
14-Files and Directories
15-Send Email Via Script
16-Curl in Scripts
17-Professional Menus
18-Wait for filesystem events with inotify
19-Introduction to grep
20-Introduction to awk
21-Introduction to sed
22- Debugging bash scripts
0 Comments