Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
7 views2 pages

Shell Scripting

The document explains the concept of a shell, specifically the Bash shell, which allows users to interact with the operating system by executing commands. It provides guidance on writing and executing shell scripts, including the use of shebang, granting execute permissions, and handling script arguments. Additionally, it suggests an assignment to practice writing scripts with commands and arguments on various Linux distributions.

Uploaded by

samreenss2414
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Shell Scripting

The document explains the concept of a shell, specifically the Bash shell, which allows users to interact with the operating system by executing commands. It provides guidance on writing and executing shell scripts, including the use of shebang, granting execute permissions, and handling script arguments. Additionally, it suggests an assignment to practice writing scripts with commands and arguments on various Linux distributions.

Uploaded by

samreenss2414
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

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

You might also like