1Which character sequence, placed at the very first line of a script, indicates the interpreter to be used for execution?
A.//bin/bash
B.#!/bin/bash
C./ /bin/bash /
D.$$/bin/bash
Correct Answer: #!/bin/bash
Explanation:The sequence #! is called the shebang. It tells the operating system which interpreter (in this case, /bin/bash) should be used to parse the rest of the file.
Incorrect! Try again.
2What is the correct syntax to assign the integer value $10$ to a variable named count in Bash?
A.count = 10
B.$count = 10
C.count=10
D.int count = 10
Correct Answer: count=10
Explanation:In Bash, there must be no spaces around the assignment operator (=). count = 10 is interpreted as running a command named count with arguments = and 10.
Incorrect! Try again.
3How do you access the value stored in a variable named username?
A.username
B.%username%
C.$username
D.@username
Correct Answer: $username
Explanation:To access or expand the value of a variable in Bash, you prefix the variable name with a dollar sign ($).
Incorrect! Try again.
4Which command is used to accept user input and store it in a variable?
A.input
B.get
C.scan
D.read
Correct Answer: read
Explanation:The read command allows scripts to accept interactive input from the user. For example: read var_name.
Incorrect! Try again.
5What is the standard file extension for Bash scripts, although not strictly required by Linux?
A..bat
B..sh
C..py
D..exe
Correct Answer: .sh
Explanation:The .sh extension is the convention for Shell scripts, helping users and editors identify the file type, though the shebang determines execution.
Incorrect! Try again.
6Which character is used to start a single-line comment in a Bash script?
A.//
B.#
C./*
D.--
Correct Answer: #
Explanation:The hash symbol (#) is used for comments. Anything following it on that line is ignored by the interpreter (except for the shebang on line 1).
Incorrect! Try again.
7Which variable represents the first argument passed to a Bash script?
A.$0
B.$1
C.$arg1
D.$#
Correct Answer: $1
Explanation:0 is the script name itself, and $2 would be the second argument.
Incorrect! Try again.
8Which variable contains the total number of arguments passed to the script?
A.$@
B.$*
C.$?
D.$#
Correct Answer: $#
Explanation:$# expands to the number of positional parameters (arguments) passed to the script.
Incorrect! Try again.
9What is the output of the expression: echo $(( 5 + 3 ))?
A.5 + 3
B.8
C.53
D.Error
Correct Answer: 8
Explanation:The $(( ... )) syntax is used for Arithmetic Expansion. It evaluates the mathematical expression inside.
Incorrect! Try again.
10Which operator is used to calculate the remainder (modulo) in Bash arithmetic?
A.//
B.mod
C.%
D.\
Correct Answer: %
Explanation:The % operator returns the remainder of a division operation. For example, echo $(( 10 % 3 )) outputs 1.
Incorrect! Try again.
11To make a script named script.sh executable, which command should be run?
A.chmod +x script.sh
B.chown +x script.sh
C.exec script.sh
D.enable script.sh
Correct Answer: chmod +x script.sh
Explanation:chmod modifies file permissions. The +x flag adds execute permission to the file.
Incorrect! Try again.
12What defines an array named fruits containing "apple", "banana", and "cherry"?
Explanation:Bash arrays are defined using parentheses () with elements separated by spaces.
Incorrect! Try again.
13Given arr=(A B C), how do you access the second element ("B")?
A.${arr[1]}
B.${arr[2]}
C.$arr(1)
D.${arr:1}
Correct Answer: ${arr[1]}
Explanation:Bash arrays are zero-indexed. Index 0 is A, and Index 1 is B. Curly braces are required for array access.
Incorrect! Try again.
14Which syntax correctly returns the length of the string stored in variable text?
A.${text.length}
B.length($text)
C.${#text}
D.${text[@]}
Correct Answer: ${#text}
Explanation:The ${#variable} syntax returns the length of the string stored in that variable.
Incorrect! Try again.
15Given str="Hello World", what does ${str:0:5} output?
A.World
B.Hello
C.Hello
D.Worl
Correct Answer: Hello
Explanation:This is string slicing. The syntax is ${variable:offset:length}. Starting at offset 0 for a length of 5 returns "Hello".
Incorrect! Try again.
16Which special variable holds the exit status of the last executed command?
A.$!
B.$$
C.$?
D.$0
Correct Answer: $?
Explanation:$? holds the return code (exit status) of the most recently executed command. 0 typically means success.
Incorrect! Try again.
17Which exit code conventionally indicates that a command executed successfully?
A.1
B.-1
C.
D.100
Correct Answer:
Explanation:In Unix/Linux, an exit status of 0 means success. Any non-zero value indicates an error.
Incorrect! Try again.
18Which conditional operator checks if a file exists and is a regular file?
A.-d
B.-f
C.-e
D.-r
Correct Answer: -f
Explanation:-f checks if a file exists and is a standard file. -d checks for directories, -e checks existence (regardless of type).
Incorrect! Try again.
19Which operator is used to compare if two integers are equal in a [ ] test condition?
A.==
B.=
C.-eq
D.===
Correct Answer: -eq
Explanation:In Bash [ ] (test) syntax, -eq is used for integer comparison. = and == are used for string comparison.
Incorrect! Try again.
20What is the correct way to close an if statement?
A.endif
B.end
C.done
D.fi
Correct Answer: fi
Explanation:Bash control structures often use the reverse spelling of the opening keyword. if is closed with fi.
Incorrect! Try again.
21Which keyword matches the start of a case statement to handle multiple patterns?
A.switch
B.case
C.select
D.match
Correct Answer: case
Explanation:The syntax is case $variable in ... esac. It is the Bash equivalent of a switch statement.
Incorrect! Try again.
22In a case statement, what sequence acts as a break to terminate a pattern block?
A.;
B.break
C.;;
D.done
Correct Answer: ;;
Explanation:Double semicolons ;; are used to terminate a specific case option, preventing fall-through to the next pattern.
Incorrect! Try again.
23Which loop iterates over a list of items?
A.while
B.until
C.for
D.loop
Correct Answer: for
Explanation:The for loop is designed to iterate over a list of items (e.g., for i in 1 2 3).
Incorrect! Try again.
24Which loop continues to execute as long as the condition is true?
A.until
B.for
C.while
D.if
Correct Answer: while
Explanation:The while loop executes code as long as the test condition evaluates to exit status 0 (true).
Incorrect! Try again.
25Which loop executes as long as the condition is false (stops when it becomes true)?
A.while
B.do-while
C.until
D.foreach
Correct Answer: until
Explanation:The until loop runs until the condition becomes true (i.e., it runs while the condition is false).
Incorrect! Try again.
26Which keywords frame the body of a for or while loop?
A.start ... end
B.do ... done
C.bin ... bash
D.{ ... }
Correct Answer: do ... done
Explanation:Loops in Bash follow the structure: for/while ...; do command; done.
Incorrect! Try again.
27Which command immediately terminates the current loop iteration and jumps to the next one?
A.break
B.exit
C.pass
D.continue
Correct Answer: continue
Explanation:continue skips the remainder of the current loop iteration and returns to the loop condition check.
Incorrect! Try again.
28Which command terminates the entire loop immediately?
A.stop
B.halt
C.break
D.return
Correct Answer: break
Explanation:break exits the loop structure entirely, resuming execution at the command following the done keyword.
Incorrect! Try again.
29What is the correct syntax to define a function named myFunc?
A.def myFunc():
B.function myFunc { }
C.myFunc() { commands; }
D.void myFunc() { }
Correct Answer: myFunc() { commands; }
Explanation:The standard POSIX syntax is name() { ... }. The keyword function (Option B) is also valid in Bash specifically, but C is the most standard shell syntax.
Incorrect! Try again.
30How do you call a function named greet with an argument "John"?
A.call greet("John")
B.greet("John")
C.greet "John"
D.execute greet "John"
Correct Answer: greet "John"
Explanation:Functions are called just like commands: by writing the function name followed by space-separated arguments.
Incorrect! Try again.
31Which keyword is used to define variables that are valid only within a function?
A.var
B.private
C.my
D.local
Correct Answer: local
Explanation:The local keyword ensures the variable is scoped only to the function, preventing it from overwriting global variables of the same name.
Incorrect! Try again.
32Which option can be added to the read command to display a prompt message to the user?
A.-m
B.-p
C.-t
D.-s
Correct Answer: -p
Explanation:The -p flag stands for prompt. Example: read -p "Enter name: " username.
Incorrect! Try again.
33What is the purpose of command substitution $(command)?
A.To run a command in the background
B.To replace a command with a comment
C.To use the output of a command as a variable or argument
D.To debug a command
Correct Answer: To use the output of a command as a variable or argument
Explanation:Command substitution allows the output of a command to replace the command name itself. E.g., today=$(date).
Incorrect! Try again.
34Which conditional operator checks if a specific directory exists?
A.-f
B.-r
C.-d
D.-x
Correct Answer: -d
Explanation:The -d operator returns true if the operand exists and is a directory.
Incorrect! Try again.
35Which Bash mode/flag prints each command before executing it, useful for debugging?
A.-e
B.-x
C.-v
D.-d
Correct Answer: -x
Explanation:set -x or running bash -x script.sh enables xtrace, which prints commands and their arguments as they are executed.
Incorrect! Try again.
36What does the logic operator && do between two commands (e.g., cmd1 && cmd2)?
A.Runs cmd2 only if cmd1 succeeds
B.Runs cmd2 only if cmd1 fails
C.Runs both commands simultaneously
D.Pipes output of cmd1 to cmd2
Correct Answer: Runs cmd2 only if cmd1 succeeds
Explanation:&& is the logical AND operator. It executes the second command only if the first command returns an exit status of 0 (success).
Incorrect! Try again.
37What does the logic operator || do (e.g., cmd1 || cmd2)?
A.Runs cmd2 only if cmd1 succeeds
B.Runs cmd2 only if cmd1 fails
C.Runs both commands in parallel
D.Redirects input
Correct Answer: Runs cmd2 only if cmd1 fails
Explanation:|| is the logical OR operator. It executes the second command only if the first command returns a non-zero exit status (failure).
Incorrect! Try again.
38Which command is used to create a shortcut for a long command (e.g., creating ll for ls -al)?
A.shortcut
B.link
C.alias
D.export
Correct Answer: alias
Explanation:The alias command creates a name that points to another command. Example: alias ll='ls -al'.
Incorrect! Try again.
39Which file in the user's home directory is commonly used to store persistent aliases and environment variables?
A..bash_history
B..bashrc
C..config
D..env
Correct Answer: .bashrc
Explanation:.bashrc is a script executed whenever a new interactive shell is started. It is the standard place for user-specific configurations.
Incorrect! Try again.
40Which command is used to reload the .bashrc file without logging out and back in?
A.reload .bashrc
B.refresh
C.source .bashrc
D.run .bashrc
Correct Answer: source .bashrc
Explanation:source (or simply .) executes the content of a file in the current shell context, updating variables and aliases immediately.
Incorrect! Try again.
41What does the tilde ~ symbol represent in Bash?
A.The root directory
B.The current working directory
C.The user's home directory
D.The last executed command
Correct Answer: The user's home directory
Explanation:~ is an expansion character that resolves to the current user's home directory (e.g., /home/username).
Incorrect! Try again.
42Which shortcut repeats the very last command executed in the terminal?
A.@@
B.!!
C.r
D.again
Correct Answer: !!
Explanation:!! is a history expansion that repeats the last command.
Incorrect! Try again.
43If you want to perform floating-point arithmetic (decimals), which external utility is commonly piped into from Bash?
A.math
B.expr
C.bc
D.float
Correct Answer: bc
Explanation:Bash built-in arithmetic ($((...))) only handles integers. bc (Basic Calculator) is used for floating-point math.
Incorrect! Try again.
44How do you check if a string variable $STR is empty in a conditional test?
A.[ -z "$STR" ]
B.[ -n "$STR" ]
C.[ "$STR" == 0 ]
D.[ -e "$STR" ]
Correct Answer: [ -z "$STR" ]
Explanation:The -z flag tests if the length of the string is zero (empty).
Incorrect! Try again.
45What does the -ne operator stand for in an integer comparison?
A.Not Empty
B.Near Equal
C.Not Equal
D.Negative
Correct Answer: Not Equal
Explanation:In integer tests ([ ... ]), -ne compares two numbers and returns true if they are not equal.
Incorrect! Try again.
46Which command allows you to view the list of previously executed commands?
A.past
B.log
C.history
D.mem
Correct Answer: history
Explanation:The history command outputs a numbered list of commands previously executed by the user.
Incorrect! Try again.
47What happens if you run a script that does not have the executable permission bit set using ./script.sh?
A.It runs in debug mode
B.Permission denied error
C.It asks for the root password
D.It runs slowly
Correct Answer: Permission denied error
Explanation:If the execution bit is not set (chmod +x), the shell refuses to execute the file directly, resulting in 'Permission denied'.
Incorrect! Try again.
48How can you specify a range of numbers from 1 to 5 in a for loop?
A.{1..5}
B.[1-5]
C.(1 to 5)
D.range(1,5)
Correct Answer: {1..5}
Explanation:Brace expansion {start..end} creates a sequence. Example: for i in {1..5}.
Incorrect! Try again.
49When defining a custom command (script) to be accessible system-wide, where is it commonly placed?
A./tmp
B./var/log
C./usr/local/bin
D./etc
Correct Answer: /usr/local/bin
Explanation:/usr/local/bin is a standard directory in the $PATH for user-created scripts and executables that should be available to all users.
Incorrect! Try again.
50Which mathematical assignment operator increments a variable by a value (e.g., )?
A.x++5
B.x += 5
C.x =+ 5
D.x :+ 5
Correct Answer: x += 5
Explanation:Inside (( ... )) or let, the += operator adds the right-hand value to the variable.
Incorrect! Try again.
Give Feedback
Help us improve by sharing your thoughts or reporting issues.