SHELL: Its a program that takes a commands from the user and pass it to the kernel.
It interacts between user and the OS(kernel)
WHICH SHELL :echo $SHELL--->Default shell used---/bin/bash
to see default env vars --run env
to see the different shell cat /etc/shells
USECASE: Everyday @9am you have to log in servers and go to some folder etc and
run some commands
Automate-->perform this task automatically -->which is manual and repetitive--
>Automation
SHELL(BASH)SCRIPTING: A text file and put a series of Linux commands and run them
---->To automates tasks in Linux systems
---->Every shell script will have .sh extention normally
How to write a shell script
============================
vi firstscript.sh
shebang-->#!/bin/bash--->it invokes bash shell, If we don't use this a default
shell will be used
#!/bin/bash
pwd
date
df -h
hostname -i
ls
echo "hello from shell script"
------------------------------------
Give execute permission to he script
chmod +x scriptfilename --->this will give execute permission to all
chmod u+x scriptfilename---->only for users execute permissions
save and exit
---------------------------
Ways to run shell script
-------------------------
./scriptfilename
sh scriptfilename
bash scriptfilename
---------------------------
============================================
Arguments--->some statements or numbers or strings or combination of all these
passed along with the script
example:./sample.sh shreeni bangalore Linux 10
1st 2nd 3rd 4th
How read the arguments passed to the script
$1--->1st argument
$2--->2nd argument
$3--->3rd argument
$4--->4th argument
-
-
-
$n
=========================
script with calling arguments
vi args.sh
#!/bin/bash
echo "i am $1"
echo "i am from $2"
echo "we are learning $3"
echo "we are $4"
echo "we do $5"
to run this
./args.sh shreeni Bengaluru Linux 7
===============================
Assignment--write more scripts with commands and arguments, run scripts in ubuntu,
redhat,centos