Bash Commands of Linux
Shell Scripting in Linux
Shell Scripting in Linux
"Before moving to Linux basic commands, first of we should know about the command shell."
What is a command shell?
- A program that interprets commands.
- It allows a user to execute commands by typing them manually at a terminal, or automatically in programs called shell scripts.
- A shell is not an operating system. It is a way to interface with the operating system and run commands.
What is BASH?
1. BASH = Bourne Again SHell.
2. Bash is a shell written as a free replacement to the standard Bourne Shell (/bin/sh) originally written by Steve Bourne for UNIX systems. It has all of the features of the original Bourne Shell, plus additions that make it easier to program with and use from the command line.
How is BASH different from the DOS command prompt?
BASH VS DOS |
Basic Terminal Shortcuts:
Before we continue to learn about Linux shell commands, it is important to know that there are many shortcuts that we are using to control terminal in Linux/UNIX.
Basic Linux Shortcuts |
comments are write using # for example:
#this is comment
For example, the following creates a shell variable and then prints it:
variable ="Hello" echo $variable
#Reading input form user
read name
echo $name
Below is a small script which will use a variable.
#!/bin/sh echo "what is your name?" read name echo "How do you do, $name?" read remark echo "I am $remark too!"
#printing arguments which are given at compile time echo $1 $2 $3
#running commands using scripting echo $pwd echo $ls echo $home
Conditional Statements:
The conditionals we are referring to are of course,
if
, then
and else
. we can also implement conditioning in shell scripting to perform operations
operators and their details are given below:
Shell script conditioning |
if/else conditioning code example |
Different loops in shell programming:
example program for For loop in shell programming:
for loop in shell programming |
while loop in shell programming |
until loop in the shell programming |
let command:
Last but not the least we have let command in shell programming which use to compute expressions such as plus, minus, and all other arithmetic operations:
let command in shell programming |
Assignment Question:
Q1. write a program do the following thing using shell script:
- Take 3 names to form user
- Execute PWD, ls, touch
- Print all the names on the console
Q2. write a program do following thing using shell script:
- print all the argument which are given while executing the output file
- print the version of the bash
- print the name of the working directory
Today's Lab Tasks Submission:
Previous Lab Tasks Submission:
This is really an amazing post, Thanks for sharing.
ReplyDeleteDevOps Training
DevOps Online Training
DevOps Training in Ameerpet
Post a Comment