Bash or Shell script tutorial
What is shell?
shell is program which interprets user commands.command may be entered by user or by read from file or may be by file it (Shell) interpreate not compiled.
What is Shell script or Bash Script?
Shell script or Bash script is collection of multiple commands to automate a specific job, it will execute the command line by line.It translate the commands and sent to system.
Types of Linux shells?
Linux operating system are consists of kernel, shell, and GUI interface (Gnome, KDE, etc.).
Some popular linux shell are:
Bourne shell − Default prompt is $.
C shell − Default prompt is %.
Categoireis of the Bourne Shell
sh shell – Bourne shell
ksh shell – Korn shell
bash – Bourne Again shell
POSIX shell (sh)
Categoireis of the C-type shells
csh – C shell
tcsh – TENEX/TOPS C shell
we can check shells on a Linux system from file /etc/shells
$ cat /etc/shells /bin/bash /bin/sh /bin/tcsh /bin/csh
we can check default shell by /etc/passwd file
$ less /etc/passwd output: kencorner:uehe7eiwfbi9eiuiue:ken kencorner:/home/kencorner:/bin/bash
for entering in another shell just enter name of new shell and hit enter.
Now Creating and executing shell scripts or bash scripts.
step 1: open vi editor
$ sudo vi firstScript.sh
Step 2: write these line
echo “Hello pal”
then save and exit from vi editor (Esc :wq!)
Note : #!/bin/sh tell the system that command next to line be executed by the Bourne shell.It is known as shebang.
echo command will display the message to the monitor.
Executing the script
Before executing the command we need to change the permission of script
$ sudo chmod -R 777 firstScript.sh
$ sudo chmod +x firstScript.sh
Now script is ready to run
$ sudo ./firstScript.sh
Output : Hello pal
# Single line comment : ' This is a multi line comment '
Some More Topic Below :
You May Also Enjoy Reading This …