Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

OPERATING SYSTEMS LAB WEEK 2 SUBMISSION

Name:- Varun Tirthani SRN:- PES1201802027 Section:- 5F

PRACTICE EXERCISE 1:- First Shell Script To Print “Hello World”


As per the manual, the shell script was written and saved as first.sh (in gedit) and later
executed and the following output was observed:

PRACTICE EXERCISE 2:- Second Shell Script To Print “Knowledge Is Power”


As per the manual, the shell script was written and saved as second (in VI Editor) and
executed after which following output was observed:

(Clear has been replaced by new line character)


EXERCISE 1:- Write the following shell script, save it, execute it and display output.

# Script to print user information who currently login, current date & time
# Enter the following commands in a file
#
clear
echo "Hello $USER"
echo "Today is ";date
echo "Number of user login : " ; who | wc -l
echo "Calendar"
cal
exit 0

The following shell script was written and saved as exer1 (in VI Editor) and on execution the
following output was observed:-
(Clear has been replaced by new line character)
In Linux, by default, if a particular shell script is executed, it returns two values to indicate
successful or unsuccessful execution. If return value is 0, that means that the script was
successfully evaluated and if the return value is nonzero, it means unsuccessful execution.
Hence the statement exit 0 at the end is to indicate successful execution of the exer1 shell
script.
$ indicates environment variables(all capital letters) created by Linux during installation or
due to user creation procedures. These variables are a set of dynamically stored values,
which are frequently accessed by system applications and processes.
PRACTICE EXERCISE 3:- Check output for environment variables.

EXERCISE 2:- If you want to print your home directory location then you give:
a) echo $HOME OR (b) echo HOME
Which of the above command is correct & why?

The first command, i.e. echo $HOME is the right command as the home directory location
is stored in the environment variable HOME and $HOME is the correct way to access
contents of the variable. echo HOME would simply print HOME on the terminal as HOME
by itself does not signify anything.

EXERCISE 3:- What is the output of the following expressions?


$ expr 1 + 3
$ expr 2 - 1
$ expr 10 / 2
$ expr 20 % 3
$ expr 10 \* 3
$ echo `expr 6 + 3`

EXERCISE 4:- What is the meaning of Single quote (‘), Double quote (“) and Back
quote (`) in shell?

For simplicity, we assume the usage of different types of quotes in echoing a variable:-
Double Quotes(“) allows the expansion of variable within the quotes, i.e. it substitutes
variables in text.
Single Quotes(‘) output the exact string within the quotes without expansion of the
variable.
Back Quotes(`) executes the content within a particular variable before outputting the
final value.
echo “$var” outputs the contents of the environment variable $HOME
echo `$var` outputs the results after executing the contents within the variable. In this case,
it states that it is a directory.

echo “$var” outputs the word “uname” that was assigned to it initially.
echo `$var` returns Linux as output after executing uname within the ``.
EXERCISE 5:- What does the following command do?
$ sort < myfile > sorted_file
Initially, myfile was created and filled with jumbled alphabets. On executing the following
command, the jumbled alphabets were arranged alphabetically in a newly created file called
sorted_file. The screenshot of the same is :
PRACTICE EXERCISE 4:- Create shell script using if-else-fi statements and execute it.

The shell script was saved as shtry (in VI Editor) and executed.

PRACTICE EXERCISE 5:- Create a shell script to print Welcome 5 times


The shell script was saved as shtry2 (in VI Editor) and executed.
PRACTICE EXERCISE 6:- Create a shell script to display numbers 0 to 9
The shell script was saved as shtry3 (in VI Editor) and executed.

PRACTICE EXERCISE 7:- Create a shell script using until loop to display numbers 0
to 9
The shell script was saved as shtry4 (in VI Editor) and executed.
EXERCISE 6:- Create a shell script (using Bourne Shell or Bash) which converts all file
names in the current directory to lowercase. You should execute the script and send a
screenshot of the output.

For this purpose two files namely DUMMY and DUMMIES were created in the directory
and these were tested against the shell script exer6 (in VI Editor) for conversion to dummy
and dummies respectively. Apart from this, the S in Screenshots has also been converted to
screenshots.

You might also like