Unit 3: Bash Scripting Fundamentals - Subjective Questions

CSC104 — It Fundamentals • Practice Questions with Detailed Answers

20 questions

1

Define Bash scripting. Explain its purpose and list the basic steps required to create and execute a Bash script.

2

Describe the standard structure of a Bash script and write a basic Hello World script.

3

Explain how variables are declared, assigned, expanded, and removed in Bash. Distinguish between local, shell, and environment variables.

4

Write and explain a Bash script that accepts a user's name and age through keyboard input and prints a formatted message.

5

Explain the purpose of comments in Bash. Distinguish between a shebang, a single-line comment, and a common technique for writing multi-line comments.

6

Describe positional arguments and special argument-related parameters in Bash. Write a script that displays the script name, first two arguments, argument count, and all arguments.

7

Explain indexed arrays and associative arrays in Bash. Demonstrate creation, access, update, traversal, and deletion.

8

What is string slicing in Bash? Explain how substrings, string length, prefix removal, and replacement are performed using parameter expansion.

9

Explain Bash file conditional expressions. Write an if statement that checks whether a supplied path is a readable regular file, a directory, or a nonexistent path.

10

Compare string and arithmetic conditional expressions in Bash. Give suitable examples of each.

11

Define exit status in Bash. Explain how $?, exit, &&, ||, and ! use command success or failure.

12

Write a Bash script using if, elif, and else to classify an integer as positive, negative, or zero. Explain the control flow.

13

Explain the case statement in Bash. Write a menu-driven example and compare it with an if-elif-else statement.

14

Compare for, while, and until loops in Bash. Provide an example of each and state when each form is appropriate.

15

Distinguish between break and continue in Bash loops. Explain their behavior in nested loops with examples.

16

Explain how functions are defined and called in Bash. Describe function arguments, local variables, output, and return status with an example.

17

Describe practical methods for debugging a Bash script. Explain syntax checking, execution tracing, strict-mode options, and diagnostic output.

18

Explain useful Bash shortcuts and command-line editing features that improve efficiency.

19

Explain how to create custom commands and aliases in Bash. Distinguish between temporary and persistent definitions.

20

Design a complete Bash script that creates a backup of a user-supplied file. The script must validate input, use a function, generate a timestamped filename, report errors, and return meaningful exit statuses.