Unit 10: Shell programming - Subjective Questions

CSE105 — Creative Engineering Workshop • Practice Questions with Detailed Answers

20 questions

1

Describe the general structure of a shell script. What are the essential components every shell script should contain?

2

Explain the process of creating and executing a shell script with all the necessary steps and commands.

3

Explain the while loop in shell scripting with its syntax and a suitable example that prints numbers from 1 to 5.

4

Explain the for loop in shell scripting. Illustrate with two examples: one iterating over a list and one using a numeric range.

5

What are functions in shell scripting? Explain how to define and call a function, including how to pass arguments.

6

Explain arrays in shell scripting. Describe how to declare, access, and iterate over array elements with examples.

7

What are Interactive Shell Scripts? Explain how the read command is used to accept user input with an example.

8

Explain Command-Line Arguments in shell scripting. Describe the special variables $0, $1, $#, $@, and $* with an example.

9

Describe the various operators in shell scripting. Explain arithmetic, relational, logical, and string operators with examples.

10

Explain the if and if-else statements in shell scripting with syntax and examples.

11

Explain the nested if and if-elif-else (nested if) constructs in shell scripting with an example that assigns grades based on marks.

12

Explain the test command and the [] (square bracket) notation in shell scripting. How are they related?

13

Explain the case statement in shell scripting with syntax. Write a script that displays a menu and performs actions using case.

14

Distinguish between the while loop and the for loop in shell scripting. When would you prefer one over the other?

15

Compare the [ ] (single bracket) and [[ ]] (double bracket) test constructs in bash. What advantages does [[ ]] offer?

16

Write a shell script using a function and a loop that calculates the factorial of a number entered by the user. Explain the logic in detail.

17

Write and explain a complete shell script that reads a list of numbers into an array, then finds and prints the largest and smallest elements.

18

Define a shell script and explain the role of the shebang (#!) line. What happens if the shebang is omitted?

19

Describe the different ways to perform arithmetic operations in shell scripts. Explain expr, $(( )), let, and bc with examples.

20

Write a shell script that uses command-line arguments, a case statement, and appropriate operators to build a simple calculator that adds, subtracts, multiplies, or divides two numbers. Explain the script.