Skip to content
Sign upLog in
← Back to Community

Shell Scripting S2: How to Write & Run First Shell Script and Importance of Shabang

Profile icon
sasivanga

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-r--r--
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 ./test.py
Python3 ./test.py
With shabang :
./test.py

#! /bin/rm

echo “ this is test “`

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

Variables :

$variablename
${variablename}
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 test.sh

‘Cat test.sh | wc -l’

Comments in shell script :

to comment

Cntrl +l ⇒ clear screen

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

Voters
Profile icon
BanShen
Profile icon
VishalJadhav5
Profile icon
fy4l
Profile icon
AtifKhan3
Profile icon
nomiDwigg
Profile icon
Highwayman
Profile icon
sasivanga
Comments
hotnewtop
Profile icon
Highwayman

Noice. You can escape characters in a post using backslashes.
example
In:

\# comment

Out:
# comment
Versus
In:

# comment

Out:

comment