The document discusses shells and shell programming. It provides information on:
- Shells provide an interface to run commands and programs and display outputs. Common shells include Bourne, C, and other derivative shells.
- Shells prompt for commands and interpret them, passing commands to the kernel for execution and displaying outputs.
- Shell scripts allow automated execution of commands through programming constructs like variables, conditionals, loops, and functions.
BACKGROUND A shell provides a command-line interface for users. I.docxwilcockiris
BACKGROUND
: A shell provides a command-line interface for users. It interprets user commands and executes them. Some shells provide simple scripting terms, such as
if
or
while
, and allow users to make a program that facilitates their computing environment. Under the hood, a shell is just another user program as you know from Minor2 assignment. The file
/bin/bash
is an executable program file for the bash shell. The only thing special about your login shell is that it is listed in your login record so that /bin/login (i.e., the program that prompts you for your password) knows what program to start when you log in. If you run "cat /etc/passwd", you will see the login records of the machine.
PROGRAM DESCRIPTION
GROUP COLLABORATIVE PORTION
: In this assignment, you will implement the shell “engine” as the group component, where all members are responsible for the following functionality.
A Command-Line Interpreter, or Shell
Your shell should read the line from standard input (i.e., interactive mode) or a file (i.e., batch mode), parse the line with command and arguments, execute the command with arguments, and then prompt for more input (i.e., the shell prompt) when it has finished. This is what Minor 2 program should do with addition of batch processing which means just reading a batch line by line and calling the same interpretation logic.
Batch Mode
In batch mode, your shell is started by specifying a batch file on its command line. The batch file contains the list of commands that should be executed. In batch mode, you should not display a prompt, but you should echo each line you read from the batch file back to the user before executing it. After a batch is finished the shell will exit.
Interactive Mode
No parameters specified on command line when the shell is started. In this mode, you will display a prompt (any string of your choice) and the user of the shell will type in a command at the prompt.
You will need to use the fork() and exec() family of system calls. You may not use the system() system call as it simply invokes the system’s /bin/bash shell to do all of the work. You may assume that arguments are separated by whitespace. You do not have to deal with special characters such as ', ", \, etc. You may assume that the command-line a user types is no longer than 512 bytes (including the '\n'), but you should not assume that there is any restriction on the number of arguments to a given command.
INDIVIDUAL PORTIONS
Build-in Commands:
Every shell needs to support a number of built-in commands, which are functions in the shell itself, not external programs. Shells directly make system calls to execute built-in commands, instead of forking a child process to handle them.
In this assignment, each member of the group will implement one of the following section and commit in GitLab the code that supports those commands:
Add a new built-in
alias
command that allows you to define a shortcut for commands by essenti.
The Korn Shell is the UNIX shell (command execution program, often c.docxSUBHI7
The Korn Shell is the UNIX shell (command execution program, often called a command interpreter) that was developed by David Korn of Bell Labs as a comprehensive, combined version of other major UNIX shells. Incorporating all the features of the C shell (csh) and the Tab C-shell (tcsh) with the script language features similar to that of the Bourne Shell, the Korn Shell is considered the most efficient shell. Korn, Bourne, and C are the 3 most commonly used UNIX shells. You will be using the Korn Shell (ksh) for this project in which you will be writing shell script files.
1.
Begin by executing the following command from a terminal session in your Ubuntu system:
sudo apt-get install ksh
You will immediately be asked to enter your password (csci345). This will install the Korn shell into your Ubuntu system on your PC or Mac for use in this project. Simply type
ksh
and to go into the Korn Shell (your system prompt will change to $ only) and then enter CTRL-D to exit out of it (your default system prompt of
[email protected]
:~$ will re-appear).
As you go through this exercise and start writing shell scripts, you will learn some additional troubleshooting tips to help you navigate through the Korn Shell (ksh).
Keep track of some of these tips (5 of them) and put them into a Word document in a list format with explanations (at least 150 words in current APA format). Make sure that these are different from those mentioned in the textbook.
2.
Do some research on what the Korn Shell is about and what it has to offer. Provide some basic information (3–5 key points) in a short report (at least 150 words in current APA format) and compile it into the same Word document as above and submit it with this project. Also, provide 5–7 positive features of the Korn Shell (ksh) in the same report (at least 150 words in current APA format) in a list. Below are 3 websites that can assist you in this effort. You will need at least 2 external references for this short report (in addition to your textbook):
-
http://kornshell.com/
-
http://www.dartmouth.edu/~rc/classes/ksh/print_pages.shtml
-
http://www.bolthole.com/solaris/ksh.html
There are many other websites out there that will give you additional help, if needed. Take a look at the ksh shell script below. There are 3 versions of essentially the same program, which is a wrapper to edit a file under SCCS version control. The basic task is to use the sccs command to “check out” a file under version control and then automatically edit the file. The script will then be used by users who may not be particularly advanced UNIX users. Hence, the need for a wrapper script. While the basic functionality is the same across all versions, the differences in safety and usability between the first version and the last (4th) version are worth noting. The first one is extremely bad: it would be written by someone who has just picked up a book on shell scripting and has decided, “I’m a programmer.
1 of 9 CSCE 3600 Systems Programming Major Assignm.docxShiraPrater50
1 of 9
CSCE 3600: Systems Programming
Major Assignment 2 – The Shell and System Calls
Due: 11:59 PM on Wednesday, November 6, 2019
COLLABORATION
You should complete this assignment as a group assignment with the other members of
your group as assigned on Canvas using our GitLab environment (i.e., the same group
you had for Major 1). If desired, you may submit only one program per group, but all
source code must be committed in GitLab. Also, make sure that you list the names of all
group members who participated in this assignment in order for each to get credit.
BACKGROUND
A shell provides a command-line interface for users. It interprets user commands and
executes them. Some shells provide simple scripting terms, such as if or while, and
allow users to make a program that facilitates their computing environment. Under the
hood, a shell is just another user program. The file /bin/bash is an executable file for
the bash shell. The only thing special about your login shell is that it is listed in your
login record so that /bin/login (i.e., the program that prompts you for your password)
knows what program to start when you log in. If you run "cat /etc/passwd", you will
see the login records of the machine.
PROGRAM DESCRIPTION
GROUP COLLABORATIVE PORTION
In this assignment, you will implement the shell “engine” as the “group” component,
where all members are responsible for the following functionality:
• A Command-Line Interpreter, or Shell
Your shell should read the line from standard input (i.e., interactive mode) or a
file (i.e., batch mode), parse the line with command and arguments, execute the
command with arguments, and then prompt for more input (i.e., the shell prompt)
when it has finished.
1. Interactive Mode
In interactive mode, you will display a prompt (any string of your choosing)
and the user of the shell will type in a command at the prompt.
2. Batch Mode
In batch mode, your shell is started by specifying a batch file on its command
line. The batch file contains the list of commands that should be executed. In
batch mode, you should not display a prompt, but you should echo each line
you read from the batch file back to the user before executing it.
You will need to use the fork() and exec() family of system calls. You may
2 of 9
not use the system() system call as it simply invokes the system’s /bin/bash
shell to do all of the work.
You may assume that arguments are separated by whitespace. You do not have
to deal with special characters such as ', ", \, etc. However, you will need to
handle the redirection operators (< and >) and the pipeline operator (|), which
will be specified in the “individual” portion of this assignment.
Each line (either in the batch file or typed at the prompt) may contain multiple
commands separate with the semicolon (;) character. Each command separated
by a ; should be run sequentially, but the shell should not print the next prompt ...
BACKGROUND A shell provides a command-line interface for users. I.docxwilcockiris
BACKGROUND
: A shell provides a command-line interface for users. It interprets user commands and executes them. Some shells provide simple scripting terms, such as
if
or
while
, and allow users to make a program that facilitates their computing environment. Under the hood, a shell is just another user program as you know from Minor2 assignment. The file
/bin/bash
is an executable program file for the bash shell. The only thing special about your login shell is that it is listed in your login record so that /bin/login (i.e., the program that prompts you for your password) knows what program to start when you log in. If you run "cat /etc/passwd", you will see the login records of the machine.
PROGRAM DESCRIPTION
GROUP COLLABORATIVE PORTION
: In this assignment, you will implement the shell “engine” as the group component, where all members are responsible for the following functionality.
A Command-Line Interpreter, or Shell
Your shell should read the line from standard input (i.e., interactive mode) or a file (i.e., batch mode), parse the line with command and arguments, execute the command with arguments, and then prompt for more input (i.e., the shell prompt) when it has finished. This is what Minor 2 program should do with addition of batch processing which means just reading a batch line by line and calling the same interpretation logic.
Batch Mode
In batch mode, your shell is started by specifying a batch file on its command line. The batch file contains the list of commands that should be executed. In batch mode, you should not display a prompt, but you should echo each line you read from the batch file back to the user before executing it. After a batch is finished the shell will exit.
Interactive Mode
No parameters specified on command line when the shell is started. In this mode, you will display a prompt (any string of your choice) and the user of the shell will type in a command at the prompt.
You will need to use the fork() and exec() family of system calls. You may not use the system() system call as it simply invokes the system’s /bin/bash shell to do all of the work. You may assume that arguments are separated by whitespace. You do not have to deal with special characters such as ', ", \, etc. You may assume that the command-line a user types is no longer than 512 bytes (including the '\n'), but you should not assume that there is any restriction on the number of arguments to a given command.
INDIVIDUAL PORTIONS
Build-in Commands:
Every shell needs to support a number of built-in commands, which are functions in the shell itself, not external programs. Shells directly make system calls to execute built-in commands, instead of forking a child process to handle them.
In this assignment, each member of the group will implement one of the following section and commit in GitLab the code that supports those commands:
Add a new built-in
alias
command that allows you to define a shortcut for commands by essenti.
The Korn Shell is the UNIX shell (command execution program, often c.docxSUBHI7
The Korn Shell is the UNIX shell (command execution program, often called a command interpreter) that was developed by David Korn of Bell Labs as a comprehensive, combined version of other major UNIX shells. Incorporating all the features of the C shell (csh) and the Tab C-shell (tcsh) with the script language features similar to that of the Bourne Shell, the Korn Shell is considered the most efficient shell. Korn, Bourne, and C are the 3 most commonly used UNIX shells. You will be using the Korn Shell (ksh) for this project in which you will be writing shell script files.
1.
Begin by executing the following command from a terminal session in your Ubuntu system:
sudo apt-get install ksh
You will immediately be asked to enter your password (csci345). This will install the Korn shell into your Ubuntu system on your PC or Mac for use in this project. Simply type
ksh
and to go into the Korn Shell (your system prompt will change to $ only) and then enter CTRL-D to exit out of it (your default system prompt of
[email protected]
:~$ will re-appear).
As you go through this exercise and start writing shell scripts, you will learn some additional troubleshooting tips to help you navigate through the Korn Shell (ksh).
Keep track of some of these tips (5 of them) and put them into a Word document in a list format with explanations (at least 150 words in current APA format). Make sure that these are different from those mentioned in the textbook.
2.
Do some research on what the Korn Shell is about and what it has to offer. Provide some basic information (3–5 key points) in a short report (at least 150 words in current APA format) and compile it into the same Word document as above and submit it with this project. Also, provide 5–7 positive features of the Korn Shell (ksh) in the same report (at least 150 words in current APA format) in a list. Below are 3 websites that can assist you in this effort. You will need at least 2 external references for this short report (in addition to your textbook):
-
http://kornshell.com/
-
http://www.dartmouth.edu/~rc/classes/ksh/print_pages.shtml
-
http://www.bolthole.com/solaris/ksh.html
There are many other websites out there that will give you additional help, if needed. Take a look at the ksh shell script below. There are 3 versions of essentially the same program, which is a wrapper to edit a file under SCCS version control. The basic task is to use the sccs command to “check out” a file under version control and then automatically edit the file. The script will then be used by users who may not be particularly advanced UNIX users. Hence, the need for a wrapper script. While the basic functionality is the same across all versions, the differences in safety and usability between the first version and the last (4th) version are worth noting. The first one is extremely bad: it would be written by someone who has just picked up a book on shell scripting and has decided, “I’m a programmer.
1 of 9 CSCE 3600 Systems Programming Major Assignm.docxShiraPrater50
1 of 9
CSCE 3600: Systems Programming
Major Assignment 2 – The Shell and System Calls
Due: 11:59 PM on Wednesday, November 6, 2019
COLLABORATION
You should complete this assignment as a group assignment with the other members of
your group as assigned on Canvas using our GitLab environment (i.e., the same group
you had for Major 1). If desired, you may submit only one program per group, but all
source code must be committed in GitLab. Also, make sure that you list the names of all
group members who participated in this assignment in order for each to get credit.
BACKGROUND
A shell provides a command-line interface for users. It interprets user commands and
executes them. Some shells provide simple scripting terms, such as if or while, and
allow users to make a program that facilitates their computing environment. Under the
hood, a shell is just another user program. The file /bin/bash is an executable file for
the bash shell. The only thing special about your login shell is that it is listed in your
login record so that /bin/login (i.e., the program that prompts you for your password)
knows what program to start when you log in. If you run "cat /etc/passwd", you will
see the login records of the machine.
PROGRAM DESCRIPTION
GROUP COLLABORATIVE PORTION
In this assignment, you will implement the shell “engine” as the “group” component,
where all members are responsible for the following functionality:
• A Command-Line Interpreter, or Shell
Your shell should read the line from standard input (i.e., interactive mode) or a
file (i.e., batch mode), parse the line with command and arguments, execute the
command with arguments, and then prompt for more input (i.e., the shell prompt)
when it has finished.
1. Interactive Mode
In interactive mode, you will display a prompt (any string of your choosing)
and the user of the shell will type in a command at the prompt.
2. Batch Mode
In batch mode, your shell is started by specifying a batch file on its command
line. The batch file contains the list of commands that should be executed. In
batch mode, you should not display a prompt, but you should echo each line
you read from the batch file back to the user before executing it.
You will need to use the fork() and exec() family of system calls. You may
2 of 9
not use the system() system call as it simply invokes the system’s /bin/bash
shell to do all of the work.
You may assume that arguments are separated by whitespace. You do not have
to deal with special characters such as ', ", \, etc. However, you will need to
handle the redirection operators (< and >) and the pipeline operator (|), which
will be specified in the “individual” portion of this assignment.
Each line (either in the batch file or typed at the prompt) may contain multiple
commands separate with the semicolon (;) character. Each command separated
by a ; should be run sequentially, but the shell should not print the next prompt ...
State of ICS and IoT Cyber Threat Landscape Report 2024 previewPrayukth K V
The IoT and OT threat landscape report has been prepared by the Threat Research Team at Sectrio using data from Sectrio, cyber threat intelligence farming facilities spread across over 85 cities around the world. In addition, Sectrio also runs AI-based advanced threat and payload engagement facilities that serve as sinks to attract and engage sophisticated threat actors, and newer malware including new variants and latent threats that are at an earlier stage of development.
The latest edition of the OT/ICS and IoT security Threat Landscape Report 2024 also covers:
State of global ICS asset and network exposure
Sectoral targets and attacks as well as the cost of ransom
Global APT activity, AI usage, actor and tactic profiles, and implications
Rise in volumes of AI-powered cyberattacks
Major cyber events in 2024
Malware and malicious payload trends
Cyberattack types and targets
Vulnerability exploit attempts on CVEs
Attacks on counties – USA
Expansion of bot farms – how, where, and why
In-depth analysis of the cyber threat landscape across North America, South America, Europe, APAC, and the Middle East
Why are attacks on smart factories rising?
Cyber risk predictions
Axis of attacks – Europe
Systemic attacks in the Middle East
Download the full report from here:
https://sectrio.com/resources/ot-threat-landscape-reports/sectrio-releases-ot-ics-and-iot-security-threat-landscape-report-2024/
Securing your Kubernetes cluster_ a step-by-step guide to success !KatiaHIMEUR1
Today, after several years of existence, an extremely active community and an ultra-dynamic ecosystem, Kubernetes has established itself as the de facto standard in container orchestration. Thanks to a wide range of managed services, it has never been so easy to set up a ready-to-use Kubernetes cluster.
However, this ease of use means that the subject of security in Kubernetes is often left for later, or even neglected. This exposes companies to significant risks.
In this talk, I'll show you step-by-step how to secure your Kubernetes cluster for greater peace of mind and reliability.
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Tobias Schneck
As AI technology is pushing into IT I was wondering myself, as an “infrastructure container kubernetes guy”, how get this fancy AI technology get managed from an infrastructure operational view? Is it possible to apply our lovely cloud native principals as well? What benefit’s both technologies could bring to each other?
Let me take this questions and provide you a short journey through existing deployment models and use cases for AI software. On practical examples, we discuss what cloud/on-premise strategy we may need for applying it to our own infrastructure to get it to work from an enterprise perspective. I want to give an overview about infrastructure requirements and technologies, what could be beneficial or limiting your AI use cases in an enterprise environment. An interactive Demo will give you some insides, what approaches I got already working for real.
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf91mobiles
91mobiles recently conducted a Smart TV Buyer Insights Survey in which we asked over 3,000 respondents about the TV they own, aspects they look at on a new TV, and their TV buying preferences.
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...UiPathCommunity
💥 Speed, accuracy, and scaling – discover the superpowers of GenAI in action with UiPath Document Understanding and Communications Mining™:
See how to accelerate model training and optimize model performance with active learning
Learn about the latest enhancements to out-of-the-box document processing – with little to no training required
Get an exclusive demo of the new family of UiPath LLMs – GenAI models specialized for processing different types of documents and messages
This is a hands-on session specifically designed for automation developers and AI enthusiasts seeking to enhance their knowledge in leveraging the latest intelligent document processing capabilities offered by UiPath.
Speakers:
👨🏫 Andras Palfi, Senior Product Manager, UiPath
👩🏫 Lenka Dulovicova, Product Program Manager, UiPath
UiPath Test Automation using UiPath Test Suite series, part 3DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 3. In this session, we will cover desktop automation along with UI automation.
Topics covered:
UI automation Introduction,
UI automation Sample
Desktop automation flow
Pradeep Chinnala, Senior Consultant Automation Developer @WonderBotz and UiPath MVP
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Ramesh Iyer
In today's fast-changing business world, Companies that adapt and embrace new ideas often need help to keep up with the competition. However, fostering a culture of innovation takes much work. It takes vision, leadership and willingness to take risks in the right proportion. Sachin Dev Duggal, co-founder of Builder.ai, has perfected the art of this balance, creating a company culture where creativity and growth are nurtured at each stage.
Elevating Tactical DDD Patterns Through Object CalisthenicsDorra BARTAGUIZ
After immersing yourself in the blue book and its red counterpart, attending DDD-focused conferences, and applying tactical patterns, you're left with a crucial question: How do I ensure my design is effective? Tactical patterns within Domain-Driven Design (DDD) serve as guiding principles for creating clear and manageable domain models. However, achieving success with these patterns requires additional guidance. Interestingly, we've observed that a set of constraints initially designed for training purposes remarkably aligns with effective pattern implementation, offering a more ‘mechanical’ approach. Let's explore together how Object Calisthenics can elevate the design of your tactical DDD patterns, offering concrete help for those venturing into DDD for the first time!
Elevating Tactical DDD Patterns Through Object Calisthenics
Shell Scripting and Programming.pptx
1. Using Shells and Shell Programming
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
2. Shell Programming : The shell provides you with an interface to the UNIX
system. It gathers input from you and executes programs based on that input.
When a program finishes executing, it displays that program's output.
A shell is an environment in which we can run our commands, programs, and
shell scripts. There are different flavors of shells, just as there are different
flavors of operating systems. Each flavor of shell has its own set of recognized
commands and functions.
Shell Prompt:
The prompt, which is called command prompt, is issued by the shell. While the
prompt is displayed, you can type a command . The shell reads your input after
you press Enter. It determines the command you want executed by looking at
the first word of your input. A word is an unbroken set of characters. Spaces
and tabs separate words.
Following is a simple example of date command which displays current date
and time:
$date
Thu Jun 2508:30:19 MST 2009
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
3. Shell Types:
In UNIX there are two major types of shells:
1. The Bourne shell. If you are using a Bourne-type shell, the default prompt is
the
$ character.
2. The C shell. If you are using a C-type shell, the default prompt is the
% character.
There are again various subcategories for Bourne Shell which are listed as follows:
• Bourne shell ( sh)
• Korn shell ( ksh)
• Bourne Again shell ( bash)
• POSIX shell ( sh)
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
4. The different C-type shells follow:
• C shell ( csh)
• TENEX/TOPS C shell ( tcsh)
The original UNIX shell was written in the mid-1970s by Stephen R. Bourne
while he was at AT&T Bell Labs in New Jersey.
The Bourne shell was the first shell to appear on UNIX systems, thus it is
referred to as "the shell".
The Bourne shell is usually installed as /bin/sh on most versions of UNIX. For
this reason, it is the shell of choice for writing scripts to use on several different
versions of UNIX.
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
5. Shell Interpretive Cycle
1. Shell issues the prompt and waits for you (user) to enter a command
2. After a command is entered, the shell scans command line for meta-characters
and expands abbreviations to recreate simplified commands.
3. It then passes on the command line to kernel for execution
4. The shell waits for the command to complete and normally can't do anything
while the command is running.
5. After the command gets executed the prompt reappear and the whole cycle is
repeated again.
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
6. Wild cards and file name generation.
When you have a number of files named in series (for
example, chap1 to chap12) or filenames with common characters
(like aegis, aeon, and aerie), you can use wildcards (also called metacharacters)
to specify many files at once. These special characters are *
(asterisk), ? (question mark), and [ ] (square brackets). When used in a
filename given as an argument to a command:
1. * An asterisk is replaced by any number of characters in a filename. For
example, ae* would match aegis, aerie, aeon, etc. if those files were in the same
directory. You can use this to save typing for a single filename (for
example, al* for alp
2.? A question mark is replaced by any single character
(so h?p matches hop and hip, but not help).
3. [] Square brackets can surround a choice of characters you’d like to match.
Any one of the characters between the brackets will be matched. For example,
[Cc]hapter would match either Chapter or chapter, but [ch]apter would match
either capter or hapter. Use a hyphen (-) to separate a range of consecutive
characters. For example, chap[13] would match chap1, chap2, or chap3.
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
7. Three Standard Files and Redirection:
Once a command begins running, it has access to three files:
1.Standard Input-It reads from its standard input file.
By default, standard input is the keyboard.
2.Standard Output-It writes to its standard output file.
If you invoke a shell command from the shell, a C program, or a REXX program
invoked from TSO READY, standard output is directed to your terminal screen
by default.If you invoke a shell command, REXX program, or C program from
the ISPF shell, standard output cannot be directed to your terminal screen. You
can specify a z/OS UNIX file or use the default, a temporary file.
3.Standard Error-It writes error messages to its standard error file.
If you invoke a shell command from the shell or from a C program or from a
REXX program invoked from TSO READY, standard error is directed to your
terminal screen by default.
If you invoke a shell command, REXX program, or C program from the ISPF
shell, standard error cannot be directed to your terminal screen. You can
specify a z/OS UNIX file or use the default, a temporary file.If the standard
output or standard error file contains any data when the command completes,
the file is displayed for you to browse.
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
8. Types of Redirection:
1.Overwrite Redirection:
Overwrite redirection is useful when you want to store/save the output of a
command to a file and replace all the existing content of that file. for
example, if you run a command that gives a report, and you want to save the
report to the existing file of the previous report you can use overwrite
redirection to do this.
“>” standard output
“<” standard input
2. Append Redirection:
With the help of this Redirection, you can append the output to the file
without compromising the existing data of the file.
“>>” standard output
“<<” standard input
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
9. 3. Merge Redirection:
This allows you to redirect the output of a command or a program to a specific
file descriptor instead of standard output. the syntax for using this is “>&”
operator followed by the file descriptor number.
“p >& q” Merges output from stream p with stream q
“p <& q” Merges input from stream p with stream q
Connecting commands: Pipe.
A pipe is a form of redirection (transfer of standard output to some other
destination) that is used in Linux and other Unix-like operating systems to
send the output of one command/program/process to another
command/program/process for further processing.
The Unix/Linux systems allow stdout of a command to be connected to stdin of
another command. You can make it do so by using the pipe character ‘|’. Pipe is
used to combine two or more commands, and in this, the output of one
command acts as input to another command, and this command’s output may
act as input to the next command and so on.
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
10. It can also be visualized as a temporary connection between two or more
commands/ programs/ processes. The command line programs that do the
further processing are referred to as filters.
This direct connection between commands/ programs/ processes allows them
to operate simultaneously and permits data to be transferred between them
continuously rather than having to pass it through temporary text files or
through the display screen.
Pipes are unidirectional i.e data flows from left to right through the
pipeline.
Syntax : command_1 | command_2 | command_3 | .... | command_N
Example :
1. Listing all files and directories and give it as input to more command.
$ ls -l | more
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
11. Shell Scripts:
The basic concept of a shell script is a list of commands, which are listed in the
order of execution. A good shell script will have comments, preceded by a
pound sign, #,describing the steps.
There are conditional tests, such as value A is greater than value B, loops
allowing us to go through massive amounts of data, files to read and store data,
and variables to read and store data, and the script may include functions.
Shell scripts and functions are both interpreted. This means they are not
compiled.
It supports less features. It supports input and output redirection operators.
Example Script:
Assume we create a test.sh script. Note all the scripts would have .sh
extension.
Before you add anything else to your script, you need to alert the system that a
shell
script is being started. This is done using the shebang construct.
For example:
#!/bin/sh
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
12. This tells the system that the commands that follow are to be executed by the
Bourne shell. It's called a shebang because the # symbol is called a hash, and
the !symbol is called a bang.
To create a script containing these commands, you put the shebang line first
and then add the commands:
#!/bin/bash
pwd
ls
Shell Comments:
You can put your comments in your script as follows:
#!/bin/bash
# this is sscasc
# Copyright (c)
sscasc.com #
Script follows
here: pwd
ls
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
13. Now you save the above content and make this script executable as follows:
$chmod +x test.sh
Now you have your shell script ready to be executed as
follows: $./test.sh
Extended Shell Scripts:
The shell is, after all, a real programming language, complete with variables,
control structures, and so forth. No matter how complicated a script gets,
however, it is still just a list of commands executed sequentially.
Following script use the read command which takes the input from the
keyboard and assigns it as the value of the variable PERSON and finally prints
it on STDOUT.
echo "What is your name?"
read PERSON
echo "Hello,$PERSON"
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
14. Job ID Versus Process ID
Background and suspended processes are usually manipulated via job number
(job ID). This number is different from the process ID and is used because it is
shorter.
In addition, a job can consist of multiple processes running in a series or at the
same time, in parallel. Using the job ID is easier than tracking individual
processes.
Nice command:-
It is used to change or set the priority of a process
syntax: $nice-value cat filename
The default priority of a process in unix is 20
The value range from 0 to 39, in linux-9 to 20.where 0 is high and 39 is lower
value.
the default value of reduction is 10.
The priority of a process can be increased only by administrator using double
minus(--).
eg:-$nice--15catlast.txt
The priority of a process can be made lower using the nice command.
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
15. Here is sample run of the script:
$./test.sh
What is your
name? vvfgc
Hello, vvfgc
Variables:
Variable is value that always changes during execution of a program. It is an
integral part of shell programming. They provide the ability to store and
manipulate information.
There are 2 types of variables. They are
• Environment variables
• User defined variables
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
16. Environment variables:
These variables are the part of the system and these are created and maintained
by the
system itself. These variables always in capital letters only.
Variable meaning
PS1- this is first prompt setting in Unix ($)
PS2- this is second prompt setting in Unix (>)
PATH- whether we are used absolute or relative path.
HOME- it stores the current root directory.
LOGNAME-it stores the login name of the user.
User defined variable:
Variables are defined as follows::
variable_name = variable_value
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
17. For example:
NAME = "sscasc"
Above example defines the variable NAME and assigns it the value "sscasc".
Variables of this type are called scalar variables. A scalar variable can hold only
one value at a time.
The shell enables you to store any value you want in a variable. For example:
VAR1="ssczsc "
VAR2=100
Accessing Values to variables:
To access the value stored in a variable, prefix its name with the dollar sign ( $):
For example, following script would access the value of defined variable NAME
and would print it on STDOUT:
NAME="vvfgc "
echo $NAME
This would produce following value:
Output: vvfgc
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
18. Read-only Variables:
The shell provides a way to mark variables as read-only by using the “read
only”command. After a variable is marked read-only, its value cannot be
changed.
For example, following script would give error while trying to change the value
of NAME:
NAME="vvfgc “
readonly NAME
NAME="Qadiri“
This would produce following result:
/bin/sh: NAME: This variable is read only.
Unsetting Variables:
Unsetting or deleting a variable tells the shell to remove the variable from the
list of variables that it tracks. Once you unset a variable, you would not be able
to access stored value in the variable.
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
19. Following is the syntax to unset a defined variable using the unset
command: unset variable_name
Above command would unset the value of a defined variable. Here is a simple
example
NAME="vvfgc"
unset
NAME
echo $NAME
Above example would not print anything. You cannot use the unset command to
unset variables that are marked readonly.
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
20. Read command :
This command is used to take the input from the user.
Syntax: $read var1 var2 var3 ….. var n
Syntax: $ read var1
The variable used along with the read command need not be preceded by the
$ symbol.
Ex: clear echo “enter ur name”
read name
echo “hello $name”
Output: enter ur name :vvfgc
Hello vvfgc
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
21. Expr command:
This command is used to perform mathematical caluculations.
Syntax: ` expr operand1 operator operand2 `
Where ( ` ) this symbol is known as grep symbol. There is always must a space
between symbol and the expr command.
Ex: clear echo “enter 2 numbers”
read a b
echo “ sum of 2 numbers is ` expr $a + $b ` “
echo “ sub of 2 numbers is ` expr $a - $b ` “
echo “ product of 2 numbers is ` expr $a * $b ` “
echo “ quotient of 2 numbers is ` expr $a /$b ` “
Note: In unix multiplication purpose we use the symbol of “*” because only * is
wild card character.
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
22. Test operator [numerical test]
Arithmetic Operators:
There are following arithmetic operators supported by
Bourne Shell.
Assume variable “a” holds 10 and variable “b” holds 20
then:
Show Examples
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
23. Operator Description Example
+ Addition - Adds values on either side of the operator `expr $a + $b` will give 30
- Subtraction - Subtracts right hand operand from left hand operand `expr $a -
$b` will give 10
* Multiplication - Multiplies values on either side of the operator `expr $a * $b`
will give 200/
/ Division - Divides left hand operand by right operand `expr $b / $a` will give 2
% Modulus - Divides left hand operand by right hand operand and returns
remainder `expr $b % $a` will give 0
=Assignment - Assign right operand in left a=$b would assign value of b into a
operand
= = Equality - Compares two numbers, if both are [ $a == $b ] would return same
then returns true. false.
!=Not Equality - Compares two numbers, if both [ $a != $b ] would return are
different then returns true. true.
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
24. It is very important to note here that all the conditional expressions would be
put inside
square braces with one spaces around them, for example [ $a == $b ] is correct
where as
[$a==$b] is incorrect.
All the arithmetical calculations are done using long integers.
Relational Operators:
Bourne Shell supports following relational operators which are specific to
numeric values.
These operators would not work for string values unless their value is numeric.
For example, following operators would work to check a relation between 10
and 20 as well as in between "10" and "20" but not in between "ten" and
"twenty".
Assume variable “a” holds 10 and variable “b” holds 20 then:
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
25. Operator Description Example:
-eq Checks if the value of two operands is equal or not, if yes then condition
becomes true. [ $a -eq $b ] is not true.
-ne Checks if the value of two operands is equal or not, if values are not equal
then condition becomes true [ $a -ne $b ] is true.
-gt Checks if the value of left operand is greater than the value of right operand, if
yes then condition becomes true. [ $a -gt $b ] is not true.
-lt Checks if the value of left operand is less than the value of right operand, if yes
then condition becomes true.[ $a -lt $b ] is true.
-ge Checks if the value of left operand is greater than or equal to the value of right
operand, if yes then condition becomes true.[ $a -ge $b ] is not true.
-le Checks if the value of left operand is less than or equal to the value of right
operand, if yes then condition becomes true [ $a -le $b ] is true.
Note here that all the conditional expressions would be put inside square
braces with one spaces around them, for example [ $a <= $b ] is correct where as
[$a <= $b] is incorrect.
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
26. Boolean Operators (or) logical operators:
There are following Boolean operators supported by
Bourne Shell.
Assume variable “a” holds 10 and variable “b” holds 20
then:
Show Examples
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
27. Operator Description Example
! This is logical negation. This inverts a true condition into false and vice versa.[ !
false ] is true.
-o This is logical OR. If one of the operands is true then condition would be true.[
$a -lt 20 - $b -gt 100 ] is true.
-a This is logical AND. If both the operands are true then condition would be true
otherwise it would be false.[ $a -lt 20 -a $b -gt 100 ] is false.
String test Operators
There are following string operators supported by Bourne Shell.
Assume variable a holds "abc" and variable b holds "efg" then:
Show Examples
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
28. Operator Description Example
= Checks if the value of two operands is equal or not, if yes then condition
becomes true. [ $a = $b ] is not true.
!= Checks if the value of two operands is equal or not, if values are not equal then
condition becomes true.[ $a != $b ] is true.
-z Checks if the given string operand size is zero. [ -z $a ] is not true. If it is zero
length then it returns true.
-n Checks if the given string operand size is non- zero. If it is non-zero length
then it returns true. [ -n $a ] is true.
Check if str is not the empty string. If it is str empty then it returns false.[ $a ] is
not false.
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
29. File Test Operators
There are following operators to test various properties associated with a Unix
file.
Assume a variable file holds an existing file name "test" whose size is 100
bytes and has read, write and execute permission on:
Show Examples
Operator Description Example
b file Checks if file is a block special file if yes then condition becomes true. [ -b
$file ] is false.
-c file Checks if file is a character special file if yes then condition becomes true.[
-b $file ] is false.
-d file Check if file is a directory if yes then condition becomes true.[ -d $file ] is
not true.
-f file Check if file is an ordinary file as opposed to a directory or special file if yes
then condition becomes true. [ -f $file ] is true.
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
30. -g file Checks if file has its set group ID (SGID) bit set if yes then condition
becomes true. [ -g $file ] is false.
-k file Checks if file has its sticky bit set if yes then condition becomes true. [ -k
$file ] is false.
-p file Checks if file is a named pipe if yes then condition becomes true.[ -p $file ]
is false.
-t file Checks if file descriptor is open and associated
with a terminal if yes then condition becomes true.[ -t $file ]is false.
-u file Checks if file has its set user id (SUID) bit set if yes then condition
becomes true.[ -u $file ] is false.
-r file Checks if file is readable if yes then condition becomes true.[ -r $file ] is
true.
-w file Check if file is writable if yes then condition becomes true.[ -w $file ] is
true.
-x file Check if file is execute if yes then condition becomes true.[ -x $file ] is true.
-s file Check if file has size greater than 0 if yes then condition becomes true.[ -s
$file ] is true.
-e file Check if file exists. Is true even if file is a directory but exists.[ -e $file ] is
true.
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
31. Control statements
The ability to control the flow of execution of program is known as control
statements . The different types of control structures are
Sequence control structure
Selection control structure
Looping control structure
Selection control structure
This type of instruction allows the shell script to be executed depending on the
condition. There are mainly 4 types of decision making instructions. They are
if-then-fi statement
if-then-else-fi statement
if-then-elif-then-else-fi statement case-esac statement
if-then-fi statement:
in this first check the condition. That condition is true then only the if block
statements will be executed otherwise the cursor transfer outside the if
condition.
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
32. Syntax: ex:
if [ condition ] if [ $a –gt 18 ]
then then
statements echo “eligible for vote”
fi fi
if-then-else-fi statement:
in this first check the condition. That condition is true then only the if block
statements will be executed otherwise the else block statements will be executed.
Syntax: ex:
if [ condition ] if [ $a –gt $b ]
then then
statements echo “a is larger than b”
else else
statements echo “b is larger than a”
fi fi
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
33. if-then-elif-then-else-fi statement:
in this first check the condition. That condition is true then only the if block
statements will be executed otherwise the cursor checks the next condition
then the second condition will be true then inside that statements will be
executed and so on. If any conditions were not true then the else block
statements will be executed.
Syntax: ex:
if [ condition 1 ] if [ $a –gt $b –a $a –gt $c]
then then
statements echo ”a is larger”
elif [ condition 2] elif [ $b –gt $c ]
then then
statements echo “ b is larger”
else else
statements echo “c is larger”
fi fi
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
34. Case-esac statement:
Syntax: case $variable in
[match1] )statements ; ;
[match2] statements ; ;
[match3] statements ; ;
: :
: :
*) statements ; ;
esac
here match1,match2 etc are the case labels.
• When a case statement is evaluated the value of variable is matched in any one
of the choices.
• When a match is found then shell executes that corresponding match
statements.
• The pair of semicolon at the end of every choices. It identifies break.
• *) indicates default class. Ex: clear echo “enter a character”
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
35. read ch
case $ch in
[a-z]) echo “entered character is lowercase letters” ; ;
[A-Z] echo “entered character is uppercase letters” ; ;
[0-9] echo “entered character isdigit” ; ;
*) echo “invalid choice” ;;
esac
Looping Control statements
In this all statements are executed repeatedly again and again as long as
condition is true.
This is also known as repetition or iteration.
Shell allows various types of looping. They are
• While loop
• Until loop
• For loop
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
36. While loop:
This is the pretested loop or entry controlled loop. In this first check the
condition, if that condition was true then control enter inside the loop
otherwise control transferred outside the loop.
Syntax: ex:
while [ condition ] while [ i –le 10 ]
do do
Statements echo “$i”
done i =` expr $i + 1 `
done
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
37. until loop:
This is also pretested loop or entry controlled loop. In this first check the
condition, if that condition was false then control enter inside the loop
otherwise control transferred outside the loop.
Syntax: ex:
until [ condition ] until [ i -ge 10 ]
do do
Statements echo “$i”
done i =`expr $i + 1 `
done
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
38. for loop:
This is a fixed execution loop. This loop is allow to execute list of statements
certain period of time.
Syntax:
for variable in value1 value2 value3….. value n do
statements
done
ex:
for i in 1 2 3 4 5
do
echo $i
i=` expr $i + 1 `
done
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
39. Command line arguments.
The Unix shell is used to run commands, and it allows users to pass run time
arguments to these commands.
These arguments, also known as command line parameters, that allows the
users to either control the flow of the command or to specify the input data for
the command.
While running a command, the user can pass a variable number of parameters
in the command line.
Within the command script, the passed parameters are accessible using
‘positional parameters’. These range from $0 to $9, where $0 refers to the name
of the command itself, and $1 to $9 are the first through to the ninth parameter,
depending on how many parameters were actually passed.
Example:
$ sh hello how to do you do
Here $0 would be assigned sh
$1 would be assigned hello
$2 would be assigned how
And so on …
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
40. Some additional commands to process these parameters.
1)Set
This command can be used to set the values of the positional parameters on
the command line.
Example:
$ set how do you do
$ echo $1 $2
how do
Here, “how” was assigned to $1 and “do” was assigned to $2 and so on.
2) shift
This command is used to shift the position of the positional parameters. i.e. $2
will be shifted to $1 all the way to the tenth parameter being shifted to $9. Note
that if in case there are more than 9 parameters, this mechanism can be used to
read beyond the 9th.
Example:
$ set hello good morning how do you do welcome to Unix tutorial.
Here, ‘hello’ is assigned to $1, ‘good’ to $2 and so on to ‘to’ being assigned to
$9. Now the shift command can be used to shift the parameters ‘N’ places.
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
41. Example:
$ shift 2
$ echo $1
Now $1 will be ‘morning’ and so on to $8 being ‘unix’ and $9 being ‘tutorial’.
Special Parameters $* and $@
There are special parameters that allow accessing all the command-line
arguments at once. $* and $@ both will act the same unless they are enclosed
in double quotes, "".
Both the parameters specify the command-line arguments. However, the "$*"
special parameter takes the entire list as one argument with spaces between
and the "$@" special parameter takes the entire list and separates it into
separate arguments.
We can write the shell script to process an unknown number of command line
arguments with either the $* or $@ special parameters −
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
42. Exit Status
The $? variable represents the exit status of the previous command.
Exit status is a numerical value returned by every command upon its
completion. As a rule, most commands return an exit status of 0 if they were
successful, and 1 if they were unsuccessful.
Some commands return additional exit statuses for particular reasons. For
example, some commands differentiate between kinds of errors and will return
various exit values depending on the specific type of failure.
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune