basics of Linux shell scripting
Linux shell script basics
=========================
1)root user #
2)normal user $
File system Hirarchy
====================
/
|
---------------------------------------------------------------------------------
| | | | | | | | |
bin sbin home tmp usr opt media root var
/bin
=====
=>user level commands
/sbin
======
=>admin level commands
/home
=======
=>Default home directory for users
/tmp
====
=>temp files and logs
/usr
====
=>user level package
which python
/usr/bin/python
/etc
========
=>It contains all the configuaration related info
========================================
How to write shell script
How to execute different ways
How to define a variable
====================================
How to write shell script
===========================
bash -> bourne again shell
How to check the default shell
================================
echo $SHELL
[venkat@server1 lss]$ env|grep -i shell
SHELL=/bin/bash
[venkat@server1 lss]$ echo $SHELL
/bin/bash
[venkat@server1 lss]$
How to check the current shell
==============================
echo $0
bash
How to check all the available shells
======================================
cat /etc/shells
[venkat@server1 lss]$ cat /etc/shells
/bin/sh
/bin/bash
How to write shell script
==========================
1)open any text editor
=>vi
=>nano
2)file extension should be .sh
ex:
sample.sh
3)comments in shell script
a)single line comment
#
1
2
#3
#4
#5
#6
#7
#8
9
10
#date: 10th March 2023
#vim
#httpd
#xyz
#date :20th March 2023
#This is my first shell script
#purpose
#display hello world
#date
#####Author name: bob@hcl.com
echo "Hello world"
How to execute different ways
=============================
1)using with interpreter
bash interpreter name is sh or bash
sh scriptname.sh
2)./scriptname.sh
a)read and execute permission must for the owner
chmod u+x scriptname.sh
b)in the first line of the script she-bang line we should add
#! ->she-bang =>It invokes the interpreter
#!/bin/bash
================================================================