Quiz Space

System Commands OPPE 2: May 2025 (May 2025 term)

Question 1

+20 marksProgramming

Motivation

We can iterate over each line from standard input by using while and read commands.

while read -r line; do
    # Process each line here
done

Problem Statement

Given /etc/passwd file as standard input (&0), extract the login shell and convert them to uppercase.

Instructions

  • Write your solution in script.sh shell script file.
  • The script should read the input from standard input (&0).
  • The output should be printed to standard output (&1).
  • No files will be provided, so you need to read from standard input.

Sample Input

root:x:0:0:root:/root:/bin/bash
user:x:1000:1000:User:/home/user:/bin/bash
Sayan:x:1001:1001:Sayan:/home/sayan:/bin/zsh

Sample Output

BASH
BASH
ZSH

Constraints

  • The input will always be in the format of /etc/passwd.
  • Login shells are the last field in each line, separated by a colon (:).

Hints

  • Try using variable manipulation solely to solve this question.

Question 2

+20 marksProgramming

Motivation

Folding

A line of text can be folded into multiple lines in two broad ways:

  • Fixed-width folding: where each line has a fixed number of characters. This can be done using the fold command in Linux.
  • Variable-width folding: where the line is folded based on the content, such as breaking at spaces or punctuation. This can be done using the grep -o command in Linux.
> cat data
123456789
> fold -w 3 data
123
456
789
> grep -o '[0-9]\+' <<< "1,23,456"
1
23
456

Unfolding

Unfolding is the reverse of folding, where multiple lines are combined into a single line. This can be done using the paste command in Linux.

> cat data
1
2
3
> paste -sd+ < data
1+2+3

Read more about them in man fold, man grep, and man paste.

Problem Statement

You are given a line of vector arithmetic expression in the form of [a1,a2,...,an]+[b1,b2,...,bn], where ai and bi are integers. Your task is to compute the result of the vector addition and return it in the same format.

Instructions

  • Write your solution in script.sh shell script file.
  • The script should read the input from standard input (&0).
  • The output should be printed to standard output (&1).
  • You can use temporary files in your current directory if required.

Sample Input

[1,2,3]+[2,6,2]

Sample Output

[3,8,5]

Constraints

  • To keep the question simple, the expressions will always be of a sum of two vectors.
  • The expressions will always be well-formed.
  • The number of elements in the vectors will be the same.

Question 3

+20 marksProgramming

Motivation

Fibonacci Numbers

Fibonacci numbers are a sequence of numbers where each number is the sum of the two preceding ones, usually starting with 1 and 1. The sequence commonly starts as follows: 1, 1, 2, 3, 5, 8, 13, 21, and so on.

Fn=Fn−1+Fn−2F_n = F_{n-1} + F_{n-2}

Problem Statement

You are given a positive integer n. Your task is to print a right triangle of n rows consisting of the first n×(n+1)/2n \times (n + 1) / 2 fibonacci numbers.

Instructions

  • Write your solution in script.sh shell script file.
  • The script should read the integer n from standard input.
  • The output should be formatted as a triangle, with each row containing the appropriate number of fibonacci numbers.

Sample Input

5

Sample Output

				1
			1	2
		3	5	8
	13	21	34	55
89	144	233	377	610

Constraints

  • n is a positive integer.
  • The padding for each row is using tabs to align the triangle.
  • The output should be formatted with each number separated by a tab.

2 more questions in this paper

Sign in with Google — it is free — to see every question with its answer and explanation, practise it in learning mode, or take it as a timed mock test.

More on the System Commands OPPE 2 May 2025 paper

The IIT Madras BS System Commands (System Commands) OPPE 2 paper sat on May 2025, in the May 2025 term (T2 2025): 5 questions for 100 marks in 180 minutes. The first 3 questions are below. Sign in with Google — it is free — to see the whole paper with its answers and explanations, in learning mode or as a timed mock test.

FeatureSystem Commands OPPE 2 May 2025 at a glance
TermMay 2025 term (T2 2025)
SubjectSystem Commands
Course codeBSSE2001
Questions5
Marks100
Duration180 min
Programming5
Official paperOPPE 2, May 2025
Negative markingNo negative marking.
Updated

Same OPPE 2, other subjects

More System Commands