SlideShare a Scribd company logo
https://github.com/syaifulahdan/os­practice|Operating System Practice |1 to 39 
OPERATING SYSTEMS PRACTICE
Working With Bash Shell
Practice : 5B

History on Bash Shell

Creating a Bash Shell Script
https://github.com/syaifulahdan/os­practice|
https://github.com/syaifulahdan/os­practice|Operating System Practice |2 to 39 
A. Objectives
1. Understanding the shell on Linux operating system.
2. Using feature history in Bash Shell.
3. Change the history feature in Bash Shell.
4. the shell prompt.
5. Configure Bash Shell to run scripts automatically.
6. Create and execute simple shell scripts via vi editor.
7. Understand the job control.
8. Understand the stack.
9. Using aliases
https://github.com/syaifulahdan/os­practice|Operating System Practice |3 to 39 
B. Basic Theory
https://github.com/syaifulahdan/os­practice|Operating System Practice |4 to 39 
1. SHELL
Shell is a Command executive, meaning the program awaits
the user's instructions, checks the syntax of the given
instruction, then executes the command.
Shell is marked with a prompt. For user use prompt $ and
for superuser use promp #.
shell type:

/bin/sh
Developed by UNIX Berkeley known as C-Shell

/bin/csh
Bourne shell, designed by Steve Bourne of AT & T

/bin/bash
Compatible with Bourne Shell and also adapting Korn-Shell's ability.
The fundamental difference between Shell is resolved almost non-
existent, except in programming and editing facilities.
https://github.com/syaifulahdan/os­practice|Operating System Practice |5 to 39 
1. SHELL
Shell is a Command executive, meaning the program awaits
the user's instructions, checks the syntax of the given
instruction, then executes the command.
Shell is marked with a prompt. For user use prompt $ and
for superuser use promp #.
shell type:

/bin/sh
Developed by UNIX Berkeley known as C-Shell

/bin/csh
Bourne shell, designed by Steve Bourne of AT & T

/bin/bash
Compatible with Bourne Shell and also adapting Korn-Shell's ability.
The fundamental difference between Shell is resolved almost non-
existent, except in programming and editing facilities.
https://github.com/syaifulahdan/os­practice|Operating System Practice |6 to 39 
2. PROFILE
At login time, the program will run some program that is:
1. /etc/profile
It contains a shell script that applies to all Linux users.
2. Profile for each user
In the home directory, the login will first check the .bash_profile file.
If no, then the .bash_login file will be searched. If .bash_login does not
exist, then look for file named .profile
3. .bashrc
This file will be executed for switching from one shell to another through
su.
4. .bash_logout
At logout, bash will search for file .bash_logout. When present, the file
will be executed before logout
https://github.com/syaifulahdan/os­practice|Operating System Practice |7 to 39 
The contents of / etc / profile:
# System wide environment and startup programs
# Functions and aliases go in /etc/bashrc
PATH=”$PATH:/usr/X11R6/bin”
PS1=”[u@h W]$ “
umask 022
USER=’id –un’
LOGNAME=$USER
MAIL=”/var/spool/mail/$USER”
HOSTNAME=’/bi n/hostname’
HISTSIZE=1000
HISTFILESIZE=1000
Export  PATH  PS1  HOSTNAME  HISTSIZE  HISTFILESIZE  USER 
LOGNAME MAIL
https://github.com/syaifulahdan/os­practice|Operating System Practice |8 to 39 
PATH merupakan daftar nama direktori. Bila sebuah instruksi
diberikan dari prompt shell, maka instruksi tersebut akan
dicari pada daftar tersebut.
PS1 adalah prompt dimana
u = Nama User
h = Nama Host
W = Nama working direktory
https://github.com/syaifulahdan/os­practice|Operating System Practice |9 to 39 
3. HISTORY
History is adapted from C-Shell, which is a record of all
the instructions that have so far been done. These
records can be viewed as history, then can be re-
selected, edited and executed. History allows the user to
re-edit complex and lengthy instructions, especially
when errors occur in the writing of instructions and
parameters.
^P (Ctrl-P) see previous instructions
^N (Ctrl-N see the next instruction
!! execution of previous instructions
!! –3 3 previous instructions will be repeated
!!88 repeat instruction no 88
https://github.com/syaifulahdan/os­practice|Operating System Practice |10 to 39 
4. BASH-SCRIPT
Bash-script is a file that contains a collection of executable
programs. For bash script execution use .
before the bash-script file which means shell and sign
execution ./ means the bash-script file is in the actual
directory.
https://github.com/syaifulahdan/os­practice|Operating System Practice |11 to 39 
5. JOB CONTROL
Job is a program execution given to the kernel. A Job is
deemed complete, when the execution of the program ends.
Execution Job is the same as the execution of the program,
both Background process and Foreground process.
https://github.com/syaifulahdan/os­practice|Operating System Practice |12 to 39 
5. EDITOR vi
Vi is a full screen editor, meaning the editor can take
advantage of the full-screen facility. Vi has 2 pieces mode,
namely:

Command line
The vi editor interprets the input as an instruction to be
executed by the editor, examples such as searching text,
changing text automatically and others.

Editing
The vi editor interprets the output as text to be inserted into
the buffer editor. At the bottom of the screen will display the
text "INSERTING".
https://github.com/syaifulahdan/os­practice|Operating System Practice |13 to 39 
At the beginning of vi run, the program enters command mode. With
pressing the "i" button will then enter editing. To return to
command mode, press the Esc key.
The keys of the vi editor text can be seen in the table as follows:
H Move cursor to left one character
J Move the cursor to the right of one character
K Pinda h kursor ke atas
L Move the cursor down
O Insert text (one line after cursor position) To exit the 5 insert lock
models next to this and
activate other keys, then we
must press the Esc key first
I Insert text (to the left of the cursor position)
A Insert text (to the right of the cursor position)
I (Shift i) Insert text (in the starting position of the line)
A (Shift a) Insert text (at the end of the line)
https://github.com/syaifulahdan/os­practice|Operating System Practice |14 to 39 
X Deleting 1 letter (to the right of the cursor position)
Dw Delete 1 word (to the right of the cursor position)
Dd Removing 1 row (to the right of cursor position)
Yy Copying 1 line
2yy Copying 2 lines
P (Paste) Displays a sentence line that has been copied with yy key.
Cw Replace 1 word that has been written to the right of the cursor position with another word
Cc Replace 1 sentence line that has been written to the right of the cursor position with
another sentence
ctrl- b Reverse one screen
ctrl- f Forward one screen
ctrl- d Forward half screen
B Move the cursor to the left of one word
W Move the cursor to the right of one word
^ Go to the beginning of the line
$ Go to the end of the line
U Cancel the last command
U Undoes all text changes on the line where the cursor is located
:! Quit temporarily from vi editor and execute another command
https://github.com/syaifulahdan/os­practice|Operating System Practice |15 to 39 
:wq Write and quite, save the file and exit
:q! Exit vi without saving
:se all Displays all set status options
:se nu Displays the line number on the left of the screen
/string Looking for strings forward
?string Looking for strings toward the back
N Forward the search for the same direction
N Continue searching for different directions
https://github.com/syaifulahdan/os­practice|Operating System Practice |16 to 39 
C. Step by Step
https://github.com/syaifulahdan/os­practice|Operating System Practice |17 to 39 
1 Login as user.
2 Open the Console Terminal and do the experiments
below and then analyze the results of the
experiment.
3 Conduct the experiments below and then analyze
the experimental results.
4 Complete the practice questions.
https://github.com/syaifulahdan/os­practice|Operating System Practice |18 to 39 
D. Experiment
https://github.com/syaifulahdan/os­practice|Operating System Practice |19 to 39 
Experiment 6 : Create and run Bash-
scripts
1. Create a p1.sh file
$ vi p1.sh
echo "bash Script Program"
2. Change the program to an executable
$ ls –l p1.sh
$ chmod +x p1.sh
$ ls –l p1.sh
https://github.com/syaifulahdan/os­practice|Operating System Practice |20 to 39 
3. Running the script
$ bash p1.sh
$ sh p1.sh
$ . p1.sh
$ ./p1.sh
4. The convention in shell script creation is expressed as
#!/ Bin/bash. Add to the p1.sh file of the convention.
$ vi p1.sh
#!/bin/bash
echo “Program bash script”
https://github.com/syaifulahdan/os­practice|Operating System Practice |21 to 39 
5. Create a p2.sh file
$ vi p2.sh
#!/bin/bash
echo “Program 2 bash script”
6. Running multiple shell programs in a single line of
instructions separated by a sign;
$ cat p1.sh ; cat p2.sh
$ ./p1.sh ; ./p2.sh
https://github.com/syaifulahdan/os­practice|Operating System Practice |22 to 39 
Experiment 7 : Job Control
1. Foreground process
2. Background Proses
$ ps x > hasil &
$ ps x
3. Each job has a single PID (unique). To see which jobs
active
$ jobs
https://github.com/syaifulahdan/os­practice|Operating System Practice |23 to 39 
4. Create a ploop.sh file. This file will never stop unless it
is pressed
Ctrl-C
$ vi ploop.sh
#!/bin/bash
while [ true ]
Do
      Sleep 10
      echo “Hallo”
done
https://github.com/syaifulahdan/os­practice|Operating System Practice |24 to 39 
5. Make a ploop.sh file into an executable. Run the
program, will display the word Hallo every 10 seconds. To
exit the program, press Ctrl-C (^ C)
$ chmod +x ploop.sh
$ ./ploop.sh
https://github.com/syaifulahdan/os­practice|Operating System Practice |25 to 39 
Experiment 8 : Manipulation stack for
Directories
1. Dirs instruction is used to view the directory stack, the
output is displayed only home directory ~
$ dirs
2. Create 3 directory pieces
$ mkdir marketing sales support
3. Dirs instruction is used to view the directory stack, the
output is displayed only home directory ~
$ dirs
https://github.com/syaifulahdan/os­practice|Operating System Practice |26 to 39 
Experiment 9 : Alias
1. Alias is a mechanism for naming aliases on one or a
group of instructions. To view aliases that have been
registered on the system:
$ alias
2. Create multiple aliases
$ alias del=’rm –i’
$ alias h=’history’
https://github.com/syaifulahdan/os­practice|Operating System Practice |27 to 39 
3. Gunakan instruksi hasil alias
$ ls
$ del hasil
$ h | more
4. To remove aliases use unalias instructions
$ unalias del
$ del files (Error Messages, why?)
https://github.com/syaifulahdan/os­practice|Operating System Practice |28 to 39 
E. Exercise
https://github.com/syaifulahdan/os­practice|Operating System Practice |29 to 39 

Exercise : Practice 5B
1 Execution of all existing profiles:
a. Edit the profile file /etc/profile and display the message
as follows:
echo 'Profile of / etc / profile'
b. Assuming your name is student, then edit all existing profiles:
/home/student /.bash_profile
/home/. student/.bash_login
/home/student /.profile
/home/student /.bashrc
https://github.com/syaifulahdan/os­practice|Operating System Practice |30 to 39 
c. Rename /home/student with your own name. , include the echo
instruction, eg On each file in
/home/student/.bash_profile:
echo "Profile from .bash_profile"
d. Do the same for other files, adjust the display with the
corresponding file name.
2 Run the user subtitute instruction, then exit with the command exit as
follows:
$ su student
$ exit
then use the - option as follows:
$ su – student
$ exit
Explain the differences between the two utilities.
https://github.com/syaifulahdan/os­practice|Operating System Practice |31 to 39 
3 Logout
a. Edit .bash_logout file, show message and hold for 5 seconds,
before execution logout
Echo "Thank you for the session given"
Sleep 5
Clear
4 History
a. Change the value of HISTSIZE from 1000 to 20
$ HISTSIZE=20
$ h
b. Use the history feature by editing the 5th line instruction from the
last instruction.
$ !­5
https://github.com/syaifulahdan/os­practice|Operating System Practice |32 to 39 
c. Repeat the last instruction. Use also ^ P and ^ N to navigate to the
history buffer
$ !!
d. Repeat the instructions on the history buffer of a certain number,
eg number 150
$ !150
e. Repeat instruction with "ls" prefix
$! ls
$!? ls?
Explain the different instructions above
https://github.com/syaifulahdan/os­practice|Operating System Practice |33 to 39 
5 Prompt String (PS)
a. Edit the .bash_profile file, replace the PS1 prompt with '>'. An
export instruction is required with the variable name of the variab le,
in order to change the PS1 variable known to all shells
PS1=’> ‘
export PS1
PS1 results experiment:
PS1=“! > “
69 > PS1=”d > “
Mon Sep 23 > PS1=”t > “
10:10:20 > PS1=”Saya=u > “
I =stD02001 > PS1=”w >”
~ > PS1=h >”
b. Change the color of the shell prompt in blue and blink.
https://github.com/syaifulahdan/os­practice|Operating System Practice |34 to 39 
6 Bash script
a. Create 3 p1sh, p2.sh, p3.sh script with their respective contents:
p1.sh
#! /bin/bash
echo “Program p1”
ls –l
p2.sh
#! /bin/bash
echo “Program p2”
Who
p3.sh
#! /bin/bash
echo “Program p3”
ps x
https://github.com/syaifulahdan/os­practice|Operating System Practice |35 to 39 
b. Run the following script and see the result:
$ ./p1.sh ; ./p3.sh ; ./p2.sh
$ ./p1.sh &
$ ./p1.sh $ ./p2.sh & ./p3.sh &
$ ( ./p1.sh ; ./p3.sh ) &
https://github.com/syaifulahdan/os­practice|Operating System Practice |36 to 39 
7 Jobs
a. Create a shell-script that does a loop with the name pwaktu.sh,
every 10 second, then save the date and time in the result file.
#!/bin/bash
while [ true ]
   Do
       date >> hasil
       Sleep 10
   Done
b. Run as background; then run one program (find utility)
$ jobs
$ find / ­print > files 2>/dev/null &
$ jobs
https://github.com/syaifulahdan/os­practice|Operating System Practice |37 to 39 
c. Make program 1 as foreground, press ^ Z and return the program
into the background
$ fg %1
$ bg
d. Stop background program with kill utility
$ ps x
$ kill [Nomor PID]
https://github.com/syaifulahdan/os­practice|Operating System Practice |38 to 39 

Practice Report : Practice 5B
1 Analyze your experimental results.
2 Do the above exercises and analyze the results.
3 Give a conclusion from this lab.
https://github.com/syaifulahdan/os­practice|Operating System Practice |39 to 39 

“Pleasure in a job makes perfection on the results 
achieved”. Aristoteles

“Believe you can. You're halfway”. Theodore Roosevelt

“You might be able to delay, but time will not wait”. 
Benjamin Franklin 

“The effort will work if someone does not give up”. 
Napoleon Hill

“Opportunity to find a better strength in us arises 
when life seems to be very challenging”. Joseph 
Campbell

More Related Content

PDF
Operating System Practice : Meeting 7- working with bash shell-a-slide
ODP
Makefile Generation From Autotools
PDF
Dependency management with Composer
PPTX
PDF
Ansible project-deploy
PDF
Scripting and the shell in LINUX
PPT
Composer - Package Management for PHP. Silver Bullet?
PPT
Learn flask in 90mins
Operating System Practice : Meeting 7- working with bash shell-a-slide
Makefile Generation From Autotools
Dependency management with Composer
Ansible project-deploy
Scripting and the shell in LINUX
Composer - Package Management for PHP. Silver Bullet?
Learn flask in 90mins

What's hot (20)

PPT
Unix Shell Scripting Basics
PDF
Create your own composer package
KEY
Crafting Beautiful CLI Applications in Ruby
PDF
PPTX
Mastering unix
PDF
Composer the right way - SunshinePHP
PDF
Ten common mistakes made with Functional Java JBCNConf18
PDF
Don't Fear the Autotools
PDF
Git::Hooks
PDF
Composer for Busy Developers - php|tek13
PDF
Common mistakes functional java vjug
PDF
Common mistakes functional java | Oracle Code One 2018
PDF
Dependencies Managers in C/C++. Using stdcpp 2014
PDF
PDF
Building robust and friendly command line applications in go
KEY
Git and GitHub
PPTX
PHP Dependency Management with Composer
ODP
OpenGurukul : Language : Shell Scripting
PDF
Unix Shell Scripting
KEY
groovy & grails - lecture 9
Unix Shell Scripting Basics
Create your own composer package
Crafting Beautiful CLI Applications in Ruby
Mastering unix
Composer the right way - SunshinePHP
Ten common mistakes made with Functional Java JBCNConf18
Don't Fear the Autotools
Git::Hooks
Composer for Busy Developers - php|tek13
Common mistakes functional java vjug
Common mistakes functional java | Oracle Code One 2018
Dependencies Managers in C/C++. Using stdcpp 2014
Building robust and friendly command line applications in go
Git and GitHub
PHP Dependency Management with Composer
OpenGurukul : Language : Shell Scripting
Unix Shell Scripting
groovy & grails - lecture 9
Ad

Similar to Operating System Practice : Meeting 8- bekerja dengan bash shell-b-slide (20)

PDF
Operating System Practice : Meeting 2-basic commands linux operating system-s...
PDF
Operating System Practice : Meeting 3 - operasi input output-slide
PDF
Operating System Practice : Meeting 9 pemrograman shell - a -slide
PDF
Bozorgmeh os lab
PDF
Operating System Practice : Meeting 6- process and manajemen proces-b-slide
PDF
Unleash your inner console cowboy
PDF
Operating System Practice : Meeting 4 - operasi file dan struktur direktori-s...
PPTX
Shell & Shell Script
PPTX
Shell & Shell Script
PDF
Bash shell programming in linux
PPTX
Operating System Laboratory presentation .ppt
PDF
Unleash your inner console cowboy
PDF
Complete Guide for Linux shell programming
PPT
PDF
Course 102: Lecture 10: Learning About the Shell
PDF
Unleash your inner console cowboy
PDF
3.1.d manual bash script guide lsstv 2.0r11
PPT
1 4 sp
PDF
linux practical exam Digvajiya collage Rajnandgaon
Operating System Practice : Meeting 2-basic commands linux operating system-s...
Operating System Practice : Meeting 3 - operasi input output-slide
Operating System Practice : Meeting 9 pemrograman shell - a -slide
Bozorgmeh os lab
Operating System Practice : Meeting 6- process and manajemen proces-b-slide
Unleash your inner console cowboy
Operating System Practice : Meeting 4 - operasi file dan struktur direktori-s...
Shell & Shell Script
Shell & Shell Script
Bash shell programming in linux
Operating System Laboratory presentation .ppt
Unleash your inner console cowboy
Complete Guide for Linux shell programming
Course 102: Lecture 10: Learning About the Shell
Unleash your inner console cowboy
3.1.d manual bash script guide lsstv 2.0r11
1 4 sp
linux practical exam Digvajiya collage Rajnandgaon
Ad

More from Syaiful Ahdan (20)

PDF
Sertifikat EC00202128391
PDF
SP2JPB - Aplikasi Sistem Pelayanan Pemesanan Jasa Perbaikan Pada Bengkel Alam...
PDF
Sertifikat ec00202059774
PDF
Sertifikat ec00202059775
PDF
Sertifikat EC00202045078
PDF
Sertifikat EC00202044723
PDF
Sertifikat EC00202023523
PDF
Sertifikat EC00201826309
PDF
Sertifikat EC00202023149
PDF
Sertifikat EC00202022868
PDF
Sertifikat EC00202021343
PDF
Sertifikat EC00202022755
PDF
Sertifikat EC00201987196
PDF
Sertifikat EC00201856484
PDF
Sertifikat EC00201856352
PDF
Sertifikat EC00201856994
PDF
Sertifikat EC00201856895
PDF
Meeting 2 introdcution network administrator
PDF
Pertemuan 5
PDF
Pertemuan 4
Sertifikat EC00202128391
SP2JPB - Aplikasi Sistem Pelayanan Pemesanan Jasa Perbaikan Pada Bengkel Alam...
Sertifikat ec00202059774
Sertifikat ec00202059775
Sertifikat EC00202045078
Sertifikat EC00202044723
Sertifikat EC00202023523
Sertifikat EC00201826309
Sertifikat EC00202023149
Sertifikat EC00202022868
Sertifikat EC00202021343
Sertifikat EC00202022755
Sertifikat EC00201987196
Sertifikat EC00201856484
Sertifikat EC00201856352
Sertifikat EC00201856994
Sertifikat EC00201856895
Meeting 2 introdcution network administrator
Pertemuan 5
Pertemuan 4

Recently uploaded (20)

PDF
A systematic review of self-coping strategies used by university students to ...
PPTX
Lesson notes of climatology university.
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Classroom Observation Tools for Teachers
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PPTX
Pharma ospi slides which help in ospi learning
PPTX
Cell Structure & Organelles in detailed.
PPTX
Microbial diseases, their pathogenesis and prophylaxis
A systematic review of self-coping strategies used by university students to ...
Lesson notes of climatology university.
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Microbial disease of the cardiovascular and lymphatic systems
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
102 student loan defaulters named and shamed – Is someone you know on the list?
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
human mycosis Human fungal infections are called human mycosis..pptx
2.FourierTransform-ShortQuestionswithAnswers.pdf
Classroom Observation Tools for Teachers
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
Final Presentation General Medicine 03-08-2024.pptx
Abdominal Access Techniques with Prof. Dr. R K Mishra
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Pharma ospi slides which help in ospi learning
Cell Structure & Organelles in detailed.
Microbial diseases, their pathogenesis and prophylaxis

Operating System Practice : Meeting 8- bekerja dengan bash shell-b-slide