Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Operating System Practical 3: Shell Scripting for File Comparison and Number Combinations , Exercises of Operating Systems

The subject name, code, and instructions for practical 3 of the operating system course (2cs304). The practical includes writing a shell script to compare the contents of two files and another script to generate all combinations of three numbers. The code and input-output examples are provided.

What you will learn

  • What is the shell script to generate all combinations of 1, 2, and 3?
  • How to write a shell script to compare the contents of two files?
  • Explain the logic behind the number combination shell script.

Typology: Exercises

2019/2020

Uploaded on 09/12/2021

mkv-patil
mkv-patil 🇮🇳

1 document

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Subject Name and Code: Operating System (2CS304)
Practical 3:
a) Write a shell script to compare the contents of two files.
Code:
file1="/home/priyal/test1.txt"
file2="/home/priyal/test2.txt"
if cmp -s "$file1" "$file2"; then
printf 'The file "%s" is the same as "%s"\n' "$file1" "$file2"
else
printf 'The file "%s" is different from "%s"\n' "$file1" "$file2"
Fi
Input and Output:
b) Write a shell script to generate all the combinations of 1, 2 and 3.
pf3

Partial preview of the text

Download Operating System Practical 3: Shell Scripting for File Comparison and Number Combinations and more Exercises Operating Systems in PDF only on Docsity!

Subject Name and Code: Operating System (2CS304)

Practical 3:

a) Write a shell script to compare the contents of two files. Code: file1="/home/priyal/test1.txt" file2="/home/priyal/test2.txt" if cmp -s "$file1" "$file2"; then printf 'The file "%s" is the same as "%s"\n' "$file1" "$file2" else printf 'The file "%s" is different from "%s"\n' "$file1" "$file2" Fi Input and Output: b) Write a shell script to generate all the combinations of 1, 2 and 3.

Code: echo "Enter three numbers" read a read b read c for i in $a $b $c do for j in $a $b $c do if [ $j != $i ] then for k in $a $b $c do if [ $k != $i ]&&[ $k != $j ] then echo $i $j $k; fi done fi done Done Input and Output: