Unit2 - Subjective Questions

CSE325 • Practice Questions with Detailed Answers

1

Explain the significance of the 'Shebang' line in a shell script. How do you change the permissions of a file to make it executable?

2

Differentiate between Environment Variables and User-Defined Variables in Linux Shell. How can a user-defined variable be converted into an environment variable?

3

Describe the usage of the expr command for arithmetic operations. What are its limitations, and how does valid shell syntax for multiplication differ when using expr?

4

Compare the usage of expr and bc for arithmetic operations. Write a shell command using bc to calculate the value of up to 4 decimal places.

5

Explain the concept of Input and Output Redirection in Linux. Describe the function of the operators >, >>, and <.

6

What is a Pipe (|) in shell scripting? How does it differ from I/O redirection? Provide an example combining both.

7

Write a shell script using a Menu-Driven approach (using case statement) to perform basic calculator operations (Add, Sub, Mul, Div) based on user choice.

8

Explain the syntax of the if-elif-else conditional statement in shell scripting. What is the role of the test command or [ ] brackets?

9

Discuss the different forms of the for loop in shell scripting with syntax and examples.

10

Distinguish between the while and until looping constructs in shell scripting.

11

How are Indexed Arrays declared and accessed in Bash? Provide a script snippet to iterate through all elements of an array.

12

What are Associative Arrays? How do they differ from Indexed Arrays? Write a snippet to declare and access an associative array.

13

Explain how User-Defined Functions are created in shell scripting. Discuss the scope of variables (local vs global) within functions.

14

How are parameters passed to a user-defined function in a shell script? How does the function access these parameters?

15

Write a shell script that accepts a filename as a command-line argument and checks if it exists, is a file, or is a directory. It should also print the file permissions.

16

Explain the significance of the following Special Variables in shell scripting: ?, $#, and $@.

17

Write a shell script to compute the Factorial of a number provided by the user using a while loop.

18

Differentiate between Hard Quoting (Single Quotes) and Soft Quoting (Double Quotes) in shell scripting with examples.

19

Describe the Command Substitution mechanism. Compare the usage of backticks ` ` and $( ).

20

Write a shell script using a for loop to generate the Fibonacci series up to terms, where is input by the user.