You are on page 1of 11

Name: Nguyễn Thị Minh Loan

ID: 20521542
Class: CS4323.N11.CTTT

OPERATING SYSTEM
LAB X’S REPORT

SUMMARY
Task Status Page
Section 2.5 Task 1 Done From 2 to 9
Task 2 Done 10
Task 3 Done 10
Task 4 Done 11

Self-scrores: 8

*Note: Export file to PDF and name the file by following format:
Student ID_LABx.pdf

1
Section 1.5
1. Task 1
 EX 2-1:

Fig 1.1.1 : Command paragraph for example 2-1


- The myvar variable that is generated and initializes the value is the string “Hi there”
- The contents of the variable are then displayed by the echo command in cases where the
string is wrapped with " ", ' ' and \

Fig 1.1.2: Results of command paragraph 2-1


- /bin/sh variables.sh is done as a symbolic link pointing to the "variables.sh" file
- After entering /bin/sh variables.sh, we press Enter to execute the command fragment
 EX 2-2:

Fig 1.2.1: Command paragraph for example 2-2


- Changing the executable property x for the file using the command: $chmod +x
try_variablebles.sh, we have
- Then we use the command: ls -l try_variables.sh to list files and directories in long list
format

2
- By default, the ls command will print the name of all the files and directories only. To get
the additional information and a cleaner view, use the flag “-l”

Fig 1.2.2: Command line execution “chmod +x try_variablebles.sh” and “ls -l try_variables.sh”
- When running try-variables.sh from the command line, we will get the following rendering
result:

Fig 1.2.3: Results of command paragraph 2-2

 EX 2-3:

Fig 1.3.1: Command paragraph for example 2-3


- Syntax [ ] to check thing event instead of test command. Expression that checks if the
content of a variable $timeofday matches the string "yes"
- The "if" command checks check true or false condition to execute the appropriate
expression
- If yes, then command echo prints the string "Good morning", otherwise (else clause) prints
the string "Good afternoon"

3
Fig 1.3.2: Results of command paragraph 2-3

 EX 2-4:

Fig 1.4.1: Command paragraph for example 2-4


- If "if" is used, only "yes" or "no" can be checked, but there are other answers. To fix that,
we use "elif" to allow the second condition to be checked inside the else
- The script below includes also prints an error message if the user doesn't enter the correct
answer “yes” or “no”

Fig 1.4.2: Results of command paragraph 2-4

 EX 2-5:

4
Fig 1.5.1: Command paragraph for example 2-5
- "echo -n" prevents adding a new line at the end of the text

Fig 1.5.2: Results of command paragraph 2-5


- If you just press Enter or other answers "yes", "no" when the shell asks a question, an error
will occur
 EX 2-6:

Fig 1.6.1: Command paragraph for example 2-6


- “foo” is a variable used in the for loop to iterate over the set of 3 elements (separated by a
space)
- 13 is here see as the same string as bar and fud

Fig 1.6.2: Results of command paragraph 2-6

5
 EX 2-7:

Fig 1.7.1: Command paragraph for example 2-7


- The list of elements in the for statement is provided by the return result of the ls f*
command and is wrapped in the $ ( ) variable expansion statement pair.
- Expanded variables enclosed in the $ (command) are only defined when the command has
finished executing
- “lpr” submits files for printing. Files named on the command line are sent to the named
printer

Fig 1.7.2: Results of command paragraph 2-7


- No files are listed on the command-line so the lpr: error
 EX 2-8:

Fig 1.8.1: Command paragraph for example 2-8


- The “while” statement allows infinite looping. “While” continuously checking the password
(password) of the user until it is equal to the string secret just accepted

Fig 1.8.2: Results of command paragraph 2-8

 EX 2-9:

6
Fig 1.9.1: Command paragraph for example 2-9
- The while_for.sh script uses the [ ] command to check the value of variable $foo is still less
than or equal to 16 or not. If there is, the command while loop will print the cumulative sum
of the variable $foo

Fig 1.9.2: Results of command paragraph 2-9

 EX 2-10:

Fig 1.10.1: Command paragraph for example 2-10


- The until command is similar to the while command, but the test condition is disabled
reverse. The loop will be stopped if the test condition is true

7
Fig 1.10.2: Results of command paragraph 2-10
- The script will fall into a loop waiting for us to log in. Until we type "user" , we will see the
screen the first picture shows the message that the until loop is over
 EX 2-11:

Fig 1.11.1: Command paragraph for example 2-11


- The "case" command will compare the contents of the variable "$timeofday" with each
string
- When it encounters the appropriate string, it will execute the command after the ) and end

Fig 1.11.2: Results of command paragraph 2-11

 EX 2-12:

8
Fig 1.12.1: Command paragraph for example 2-12

Fig 1.12.2: Results of command paragraph 2-12

 EX 2-13:

Fig 1.13.1: Command paragraph for example 2-13

Fig 1.13.2: Results of command paragraph 2-13

2. Task 2

9
Fig 2.1: The program allows to enter the name and mssv

Fig 2.2: Result of the program

3. Task 3

Fig 3.1: The program allows to enter a number n

Fig 3.2: Result of the program

4. Task 4
10
Fig 4.1: The program that allows input of a string

Fig 4.2: Result of the program

11

You might also like