0% found this document useful (0 votes)
5 views14 pages

Understanding Kernels and Shells in OS

The document provides an overview of key concepts related to the shell and kernel in operating systems, including definitions, types of shells, and shell scripting. It covers how to create and execute shell scripts, use commands, and implement control structures like loops and conditionals. Additionally, it discusses the use of aliases and the history command for managing user commands in a shell environment.

Uploaded by

sadwho6
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views14 pages

Understanding Kernels and Shells in OS

The document provides an overview of key concepts related to the shell and kernel in operating systems, including definitions, types of shells, and shell scripting. It covers how to create and execute shell scripts, use commands, and implement control structures like loops and conditionals. Additionally, it discusses the use of aliases and the history command for managing user commands in a shell environment.

Uploaded by

sadwho6
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

• What is a Kernel?

• Interface between hardware and Software

Browser, sendmail
Software

Operating System GUI, bash, csh

Program

CPU, Memory, HD

By: Imran Afzal


• What is a Shell?
• Its like a container
• Interface between users and Kernel/OS
• CLI is a Shell

• Find your Shell


• echo $0
• Available Shells “cat /etc/shells”
• Your Shell? /etc/passwd

• Windows GUI is a shell


• Linux KDE GUI is a shell
• Linux sh, bash etc. is a shell
By: Imran Afzal
• sh
• bash
• ksh
• csh

• Type shell name e.g. csh


• Type exit to exit out of shell

By: Imran Afzal


• What is a Shell Script?
A shell script is an executable file containing multiple shell commands that are executed
sequentially. The file can contain:

• Shell (#!/bin/bash)
• Comments (# comments)
• Commands (echo, cp, grep etc.)
• Statements (if, while, for etc.)

• Shell script should have executable permissions (e.g. -rwx r-x r-x)
• Shell script has to be called from absolute path (e.g /home/userdir/[Link])
• If called from current location then ./[Link]

By: Imran Afzal


• Output to screen using “echo”

• Creating tasks
• Telling your id, current location, your files/directories, system info
• Creating files or directories
• Output to a file “>”

• Filters/Text processors through scripts (cut, awk, grep, sort, uniq, wc)

By: Imran Afzal


Input and Output of Script
• Create script to take input from the user

read
echo

By: Imran Afzal


• If then statement

If this happens = do this


Otherwise = do that

By: Imran Afzal


• For loops

Keep running until specified number of variable


e.g: variable = 10 then run the script 10 times
OR
variable = green, blue, red (then run the
script 3 times for each color.

By: Imran Afzal


• do while

The while statement continually executes a block of statements while a


particular condition is true or met

e.g: Run a script until 2pm

while [ condition ]
do
command1
command2
commandN
done

By: Imran Afzal


• Case

If option a is selected = do this


If option b is selected = do this
If option c is selected = do this.

By: Imran Afzal


• Aliases is a very popular command that is used to cut down on lengthy and
repetitive commands

alias ls="ls -al“


alias pl=“pwd; ls”
alias tell=“whoami; hostname; pwd”
alias dir="ls -l | grep ^d"
alias lmar=“ls –l | grep Mar”
alias wpa= "chmod a+w"
alias d="df -h | awk '{print \$6}' | cut -c1-4"

By: Imran Afzal


• User = Applies only to a specific user profile
• Global = Applies to everyone who has account on the system

• User = /home/user/.bashrc
• Global = /etc/bashrc

alias hh=“hostname”

By: Imran Afzal


• Command “history”

By: Imran Afzal

You might also like