0% found this document useful (0 votes)
14 views

5

The document discusses different types of shells including command line shells and graphical user interface shells. It explains the basic components and workflows of both command line interfaces and graphical user interfaces when interacting with an operating system. Specific shells and commands are also described like Bash, PowerShell, echo and sleep.

Uploaded by

lgugunashvili
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)
14 views

5

The document discusses different types of shells including command line shells and graphical user interface shells. It explains the basic components and workflows of both command line interfaces and graphical user interfaces when interacting with an operating system. Specific shells and commands are also described like Bash, PowerShell, echo and sleep.

Uploaded by

lgugunashvili
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
You are on page 1/ 5

shell - user interface or program that provides an interactive way for users to interact with OS

or execute commands. Shells are key tools for users to manage the resources and processes of a
computer system. Shells are used for managing processes, providing access to system resources,
controlling the flow of data between programs, interpreting commands from users side.
There are two main types of shells:

* Command-line Shells - text-based interface for interacting with an operating system or a computer
system through a command-line interface(CLI). It allows users to enter
text commands, typically in the form of text strings, and receive text-based responses from the
system. Command-line shells are powerful tools for administration and development,
as they provide precise control over the system and can be used for various tasks, such as file
management, process control, system configuration, and automation.(ex Linux terminal)

Graphical User Interface(GUI) Shell - GUI shell provides a graphical interface for users to interact
with the operating system. Instead of typing commands, users interact with icons, windows, menus,
and buttons using a mouse or touch input.
Examples:Windows Explorer shell on Windows, the macOS Finder,Linux desktop environments
like GNOME.

Both GUI (Graphical User Interface) and CLI (Command-Line Interface) commands ultimately get
translated to operating system actions through a series of interactions involving various
software components and layers
regardless of the interface used, OS job is to manage hardware resources, execute system calls,
ensure that requested actions are carried out securely and efficiently.

GUI command flow:


*User Input - The user interacts with the GUI using a mouse, keyboard, or touch input.*
*Graphical Interface - The GUI provides a visual interface for the user and interprets user input.
It includes elements like windows, buttons, and menus.
*GUI Libraries - GUI libraries manage the user interface elements and handle user events such as
clicks and keyboard input.
*Application Logic - The application code processes user events, triggering specific actions or
functions. ex: clicking a "Save" button may trigger a file-saving function.
*OS API - The application communicates with the operating system through an API
(Application Programming Interface). It sends requests to the OS for actions like file operations,
window management, or hardware interactions.
*System Calls - OS handles these API requests by making system calls. System calls are low-level
functions that interact with the kernel to perform tasks such as file I/O, process management,
and hardware control.
*Kernel - Core of the OS. It manages hardware resources, enforces security, handles system calls.
When a system call is made, the kernel takes over and performs the requested action, ensuring
proper permissions and resource allocation.
*Hardware - Kernel interacts directly with hardware components, such as the CPU, memory,
storage devices, and peripherals, to execute the requested actions.
*Response - kernel provides the necessary results or responses back to the application, which
can then update the graphical interface or provide feedback to the user.
*User Feedback - The updated GUI/application interface reflects the outcome of the user's
command, allowing the user to see the results of their actions.

CLI command flow:


*User Input - User enters a text-based command into the command-line interface, terminal or shell.
*Shell - The command is processed by the shell, which interprets the text input. The shell
identifies the command name, arguments, options, and any pipes or redirects
*Shell Built-ins - If the command is a shell built-in, ex: 'echo' the shell can execute it
directly without invoking an external program
*External Programs - If the command is not a built-in, shell searches for the executable
program or script associated with the command in the system's PATH
*OS API - When an external program is executed, it communicates with the operating system
through
API. Program sends requests to the OS for actions like file operations, process management and
more
*System Calls -OS handles these API requests by making system calls. System calls are low-level
functions that interact with the kernel to perform tasks such as file I/O, process creation,
memory allocation.
*Kernel - Core of the OS. It manages hardware resources, enforces security, handles system calls.
When a system call is made, the kernel takes over and performs the requested action, ensuring
proper permissions and resource allocation.
*Hardware - Kernel interacts directly with hardware components, such as the CPU, memory,
storage devices, and peripherals, to execute the requested actions.
*Response - kernel provides the necessary results or responses back to the executing program.
This could be data read from a file, a status code, or other relevant information.
*Program Output - external program, if it generates output, displays the results in the terminal
or redirects it to files or other destinations as designed.
*User Feedback - The user sees the output and any relevant messages in the terminal, allowing
them to review the results of their command.

Command lines are powerful tools in Linux; they’re the basis on which many of the friendlier GUI
tools are built. They can be accessed without the help of a GUI, they can be scripted
terminal - text-based interface that allows you to interact with your computer using text commands,
aka "command line interface" (CLI) or "shell." The terminal provides a way
for users to input commands and receive text-based responses from the operating system.
Terminals can be used to connect to remote servers and systems through protocols like SSH (Secure
Shell), allowing you to manage remote machines from your local terminal.

Windows Command Prompt - called "cmd" or simply "Command Prompt," is a command-line


interpreter
application available in most versions of the Microsoft Windows OS. It provides a text-based
interface for interacting with the OS, running commands, and performing various tasks.
*Batch Files -batch files with a .bat extension used to automate sequences of commands.
*<command> /? - /? option used with many commands to display their help information.

Windows PowerShell - powerful command-line shell and scripting language developed by


Microsoft.
Designed to help administrators and advanced users automate tasks and manage Windows systems
more
efficiently. PowerShell offers significant advantages over the traditional cmd because of its
more advanced scripting capabilities, object-oriented approach, and access to a wide range of
system administration tasks and functions.
Cmdlets -PowerShell uses cmdlets (command-lets) as its fundamental units of operation. Cmdlets
are small, task-specific commands that can be used to perform various operations.
ex: Get-ChildItem is equivalent of Linux ls command
Powershell Scripting - PowerShell allows you to write scripts that can automate complex tasks.
You can create .ps1 script files that contain a sequence of PowerShell commands.

Aliases - In PowerShell, aliases are shortcuts or alternate names for cmdlets, functions,scripts.
Aliases allows users to use shorter and more familiar names for commands. PowerShell includes
several built-in aliases, and users can also create their own custom aliases.

Bash("Bourne-Again Shell") - widely used Unix shell(command-line interpreter), in the Unix and
Linux operating systems. It is the default shell for many Linux distributions and macOS.
Bash provides a command-line interface (CLI) for users to interact with the operating system by
entering text commands. widely used in scripting and automation tasks.

.sh file extension is commonly used to denote shell script files in Linux and other OS.
Shell scripts are plain text files containing a series of commands and instructions that are
executed by a shell interpreter, such as Bash (Bourne-Again Shell) or another compatible shell.

'echo' - command in Linux, used to print text or output to the terminal. It is one of the most
basic and frequently used commands in shell scripting.

'sleep' - command used to introduce a delay or pause in the execution of a shell script or command.
It allows you to specify the amount of time in seconds for which the script or command
should be paused before continuing execution. template: sleep time_in_seconds.
*sleep command is often used in shell scripts and automation tasks to introduce delays between
commands or to schedule tasks at specific intervals. It's a simple and effective way to control
the timing of script execution.

The "shebang" - also known as a "hashbang" or "pound-bang." is a special line of text that appears
at the very beginning of a script or executable file, specifically in Unix-like operating systems.
The shebang line is used to specify the interpreter that should be used to execute the
script or program. shebang template: #!/path/to/interpreter
*The shebang line is key for making a script executable without explicitly specifying the
interpreter each time you run it. It simplifies the execution process and ensures that the correct
interpreter is used, even if the user does not explicitly specify it.
*Exmaple: If Bash script starts with the shebang #!/bin/bash, you can run the script by simply
typing its filename, and the system will automatically use the Bash shell to execute it.

File permissions determine who can access a file or directory and what actions(read, write, execute)
they can perform on it. File permissions are represented by a set of characters, and they can be
viewed and modified using the 'ls -l' and 'chmod' commands. template: { -rwxrwxr-- ...
file_name.txt }
r (read) - Allows the user to view the contents of the file.
w (write) - Allows the user to modify the file's contents or delete it.
x (execute) - For regular files, allows the user to execute the file as a program.
For directories, it allows the user to access the directory and list its contents.

Permissions are assigned to three categories of users:


*Owner - The user who owns the file or directory.
*Group - A group of users who share the same permissions on the file or directory.
Multiple users can belong to the same group.
*Other - Everyone else who is not the owner and not part of the group.

'chmod' - command in Linux is used to change the permissions (file mode) of files and directories.
It allows user to specify who can read, write, and execute a file or directory.
*Permission Types: r (read), w (write), x (execute)
*Permission Modes:
u (user) - Refers to the owner of the file or directory.
g (group) - Refers to the group associated with the file or directory.
o (others) - Refers to users who are neither the owner nor part of the group.
a (all) - Refers to all three categories (user, group, and others).
*Permission Symbols:
+ (plus) - Adds the specified permission.
- (minus) - Removes the specified permission.
= (equal) - Sets the specified permission and removes all others.
example: chmod +rx script.sh
After making it executable, you can run the script by specifying its filename ./file_name.txt

variables - used to store data and information that can be accessed and manipulated within a
shell session. Shells like bash, allow you to work with variables to store and manage data,
which can be text strings, numbers, or any other type of information.
*You can assign a value to a variable using the = operator with no spaces around it.
example: user1='timmy' year=2023
*To access the value stored in a variable, you can use the $ symbol followed by the variable name
example: echo ' hello $user1, current year is $year
*Unsetting Variables - unset (remove) a variable using the unset command
*Environment Variables - global variables that can be accessed by processes spawned from the
shell.
They are often used to store system-wide configuration and information. Common environment
variables:
PATH (specifies where executable files are located),HOME (points to the user's home directory).
*Local Variables - specific to the current shell session or script and are not accessible to other
processes or scripts. They are typically created and used within a shell script or function.
*Special Variables - Shells also provide a set of special variables with predefined meanings.
ex: $0 - the name of the script or shell, $1, $2, etc., command-line arguments, $? the exit status
of the last executed command.
*To capture the output of a command and store it in a variable in a Bash script, you can use
command substitution by using $(). example: user=$(whoami)

arguments - Shell arguments, or command-line arguments or positional parameters, are values that
are
passed to a shell script or a command when it is executed in a terminal or shell. These arguments
provide a way to pass input data or options to a script or command, allowing them to be more
flexible
and customizable. Shell scripts and commands can access and process arguments to perform
specific tasks

'export' - command to make a variable available as an environment variable. Environment variables


are
accessible to child processes, subshells, and other commands invoked from the current shell session.
example: export default_user='lina'

exported variables are available to child processes and scripts but do not affect the parent shell's
environment. To make an environment variable permanent and available across sessions, add the
export
command to your shell's startup files (e.g., ~/.bashrc, ~/.bash_profile,..) to ensure it's set
every time you start a new shell session.

.bashrc file - script that's executed whenever you start an interactive Bash shell session. It is
located in your home directory, and its purpose is to set up your shell environment by defining
various settings and customizations. Users can define custom environment variables in .bashrc

In Bash, you can perform arithmetic operations using variables by using the $((...)) construct.
This construct allows you to evaluate arithmetic expressions and store the result in a variable.
*$((...)) construct is used for integer arithmetic, it cant perform floating-point calculations
ex: num1=$(( 15 * 23 ))

RANDOM variable is a built-in environment variable that generates a random integer between
[0 and 32,767] each time it is referenced. You can use this variable to generate random
numbers in your shell scripts

'>' operator - used to redirect the standard output (stdout) of a command to a file.If the file
specified does not exist, it will be created. If it already exists, its content will be overwritten.
'>>' operator - used to append the standard output (stdout) of a command to a file. If the file
specified does not exist, it will be created. If it already exists, the new output will be added
to the end of the file, preserving the existing content.

In Linux, the pipe (|) is an operator used to connect the standard output of one command to the
standard input of another command. Allows users to create a chain of commands where the output
of
one command serves as the input to the next command. This is known as "piping" commands
together.
template: command1 | command2 | command3 | ...

grep(Global Regular Expression Print) - command-line utility in Linux that is used for searching
text or regular expressions in files. grep allows you to search for patterns within one or more
files or to search for text piped from another command. It is commonly used for text processing
and data extraction tasks.
template1: grep "pattern" filename.txt; template2: some_command | grep "pattern"

bc(Basic Calculator) - command-line calculator utility available in Linux. bc is used for


performing mathematical calculations, including arithmetic operations, numeric comparisons...
It provides a simple and versatile way to perform calculations directly from the terminal.
ex: echo "2 ^ 3" | bc -> 8; echo "13.3 * 7.5" | bc -> 99.7

You might also like