Skip to content
Shell Scripting S2: How to Write & Run First Shell Script and Importance of Shabang
Profile icon

Session - 2. How to Write & Run First Shell Script and Importance of Shabang

How to print script name

#!/bin/sh Ech “ name of the script $0”

#!/bin/sh echo " scriptname is $#"

###Shll script
rw- ==>User permissions
r--==> group permissions
r-- ⇒ other permissions

####Importance of sha-bag:

#---> sharp
!---> explanation or bang symbol
#! → Sharp bang ====> sha-bang==>shebang
Which purpose :

By using sha-bang ,we can specify the interpreter (command) which is responsible to execute the script

**Without shabang : **

`$/usr/bin/python3 ./
Python3 ./
With shabang :

#! /bin/rm

echo “ this is test “`

./ =====> it wil remove the file as shabang it pointing to rm

Variables :

echo Name⇒ Name
echo $Name⇒ Valid
echo ‘$Name’==> not valid
echo “$Name” ===> Valid

If we use single quotes then variable substitution won't be happened

###Command substitution :

Old style: ===> back quote symbolcommand`

New style : $(command)

Thse are two types of command substitution
Back quote its not single quote

**To display today date **

date⇒ it will display both date and time
Date ===+D%==>display only date
Date +t%==> display only time
echo “ today date is : date +%D’”

echo "the no of file in dir is : $(ls | wc -l)"
the no of file in dir is : 8
##To display number of lines present in

‘Cat | wc -l’

Comments in shell script :

to comment

Cntrl +l ⇒ clear screen

Increase the font : ctrl+shift+plus
Decrease the font : ctrl+ minus

You are viewing a single comment. View All
Profile icon

Noice. You can escape characters in a post using backslashes.

\# comment

# comment

# comment