
- •Management processes
- •1 Purpose of
- •2 Key provisions
- •2.1 Process control: general
- •2.2 Kill command
- •2.3 Priorities processes. Nice command
- •2.4 Ps command
- •2.5 Nohup command
- •2.6 At command
- •2.7 Program cron
- •3 Control questions
- •4 Homework
- •5 Laboratory assignment
- •6 Requirements for the content of the protocol
- •Readdress of input/output, conveyor
- •1 Purpose of
- •2 Key provisions
- •2.1 Standard streams
- •2.2 Pereadrssatsiya standard input / output
- •2.3 Variable noclobber
- •2.4 Device /dev/null
- •2.5 Redirecting stdin using exec
- •3 Key Questions
- •4 Homework
- •5 Laboratory assignment
- •6 Requirements for the content of the protocol
2.5 Redirecting stdin using exec
Consider a few files containing examples of the possible use of the system call exec.
Redirecting stdin using 'exec'.
#! /bin/bash
# redirecting stdin using 'exec' .
exec 6 <& 0 # Link file descriptor. # 6 from the standard input
(stdin).
# Saving stdin.
exec <data-file #stdin replaced by file "data - file"
read a1 # Reads the first line of "data-file".
read a2 # Read the second line of "data-file."
echo
echo "The following lines were read from the file."
echo "---------------------------------------------------------"
echo $a1
echo $a2
echo; echo; echo
exec 0<& 6 6<&-
#Rehabilitating stdin from decr. #6, where it was previously saved,
#+ and descr. #6 closing ( 6<&- ) relisting it for another processes.
#
# <&6 6<&- gives the same result.
echo -n “Enter string ”
read b1 #Now function “reed” receives data from ordinary stdin.
echo “String received from stdin.”
echo “-----------------------------------”
echo “b1 = $b1”
echo
exit 0
Similarly, the construction exec> fdename redirects output to stdout in specified file. After , the whole output from teams, which usually sent to stdout, now output in this file.
#! /bin/bash
#reassign-stdout.sh
LOGFILE=logfile.txt
Exec 6>&1 # Bind descr. #6 with stdout.
# Saving stdout.
Exec > $LOGFILE # Stdout is changed by file “logfile.txt”.
#-------------------------------------------------------------------------------------------------------#
# All enter from commands in this block is writing into the file
&LOGFILE.
Echo -n “Logfile: ”
Date
Echo “-----------------------------------------------”
Echo
Echo “Enter command \”ls - al\””
Echo
ls -al
echo; echo
echo “Output of commad \”df\””
echo
df
#--------------------------------------------------------------------------------------------------------#
exec 1>&6 6>&- #Restore stdout and close descr. #6.
echo
echo “== stdout restored in default value == ”
echo
ls -al
echo
exit 0
3 Key Questions
What is I / O flow?
What is necessary to redirect I / O streams?
Operators to redirect input / output.
What channel?
What do you know the standard streams and how do they work?
4 Homework
Examine the key provisions.
Written reply to the control questions.
Prepare for the lab assignments.