Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.

Unit 3 MCQs Bash Scripting Fundamentals

CSC104 — It Fundamentals 60 questions. Pick an option to check it.

Read the notes Subjective questions

0 of 60 answered 0 right 0 wrong , 60 left

  1. Question 1 of 60 Introduction to Bash scripting Easy

    What is a Bash script?

  2. Question 2 of 60 Bash script structure Easy

    Which line is commonly used as the shebang at the beginning of a Bash script?

  3. Question 3 of 60 Hello World Easy

    Which Bash command displays Hello World on the terminal?

  4. Question 4 of 60 Variables Easy

    Which statement correctly assigns the value Alice to a Bash variable named name?

  5. Question 5 of 60 User input Easy

    Which Bash command reads keyboard input into a variable named username?

  6. Question 6 of 60 Comments Easy

    Which symbol begins a single-line comment in a Bash script?

  7. Question 7 of 60 Arguments Easy

    Which special parameter represents the first argument passed to a Bash script?

  8. Question 8 of 60 Arrays Easy

    Which expression accesses the first element of a Bash array named colors?

  9. Question 9 of 60 String slicing Easy

    If word="BashScript", what does ${word:0:4} produce?

  10. Question 10 of 60 Conditional expressions (file, string, arithmetic) Easy

    Which Bash test checks whether a file stored in $file exists?

  11. Question 11 of 60 Exit status Easy

    What does an exit status of 0 normally mean in Bash?

  12. Question 12 of 60 If-else statements Easy

    Which keyword closes an if statement in Bash?

  13. Question 13 of 60 Switch-case statements Easy

    Which keyword closes a Bash case statement?

  14. Question 14 of 60 Loops (for, while, until) Easy

    Which loop repeats commands for each item in a list?

  15. Question 15 of 60 Break and continue statements Easy

    What does break do when it is executed inside a Bash loop?

  16. Question 16 of 60 Functions Easy

    How is a Bash function named greet commonly called after it has been defined?

  17. Question 17 of 60 Debugging Easy

    Which command enables execution tracing in a Bash script?

  18. Question 18 of 60 Shortcuts Easy

    Which keyboard shortcut commonly stops the command currently running in a terminal?

  19. Question 19 of 60 Custom commands Easy

    What is generally required before a Bash script can be run directly as ./myscript.sh?

  20. Question 20 of 60 Persistent changes Easy

    Where can a user commonly place an alias so that it is available in future Bash sessions?

  21. Question 21 of 60 Introduction to Bash scripting Medium

    A script named report.sh has execute permission and begins with #!/usr/bin/env bash. What happens when the user runs ./report.sh?

  22. Question 22 of 60 Bash script structure Medium

    Which sequence gives a sensible structure for a Bash script that must stop when a required command fails?

  23. Question 23 of 60 Hello World Medium

    Which command reliably prints Hello World followed by a newline without depending on shell-specific handling of escape sequences?

  24. Question 24 of 60 Variables Medium

    Assume file="annual report.txt". Which command passes the entire filename to wc as one argument?

  25. Question 25 of 60 User input Medium

    A script must read a full name, including spaces, into the variable name without displaying the input. Which command is appropriate?

  26. Question 26 of 60 Comments Medium

    Why does # not begin a comment in the command echo "Status: #ready"?

  27. Question 27 of 60 Arguments Medium

    A script must forward all of its positional arguments to another command while preserving each original argument boundary. Which expansion should it use?

  28. Question 28 of 60 Arrays Medium

    Given files=("first draft.txt" "final.txt" "notes.md"), which loop processes each filename as one complete value?

  29. Question 29 of 60 String slicing Medium

    Given code="BASH2025", what does ${code:4:2} produce?

  30. Question 30 of 60 Conditional expressions (file, string, arithmetic) Medium

    Which condition succeeds only when path refers to an existing regular file and count is greater than or equal to ?

  31. Question 31 of 60 Exit status Medium

    What is printed by grep -q "root" /etc/passwd; status=$?; echo "$status" when grep finds a matching line?

  32. Question 32 of 60 If-else statements Medium

    A script should print available only if service --check succeeds; otherwise, it should print unavailable. Which construct does this correctly?

  33. Question 33 of 60 Switch-case statements Medium

    Which case pattern matches filenames ending in either .jpg or .png?

  34. Question 34 of 60 Loops (for, while, until) Medium

    Assume attempt=0. Which loop runs a command repeatedly until it succeeds, while incrementing attempt after each failure?

  35. Question 35 of 60 Break and continue statements Medium

    Inside a loop over filenames, the script should skip directories but stop entirely when it encounters STOP. Which statements implement that behavior?

  36. Question 36 of 60 Functions Medium

    A function must return a calculated text value such as report.txt to its caller. Which approach is appropriate?

  37. Question 37 of 60 Debugging Medium

    A script should display expanded commands only around a suspicious section and then return to normal execution. Which pair of commands should surround that section?

  38. Question 38 of 60 Shortcuts Medium

    In an interactive Bash session, which shortcut searches backward through command history as the user types part of an earlier command?

  39. Question 39 of 60 Custom commands Medium

    A user creates an executable script named backup in $HOME/bin, but typing backup reports command not found. The script works with $HOME/bin/backup. What is the most likely fix?

  40. Question 40 of 60 Persistent changes Medium

    A user adds export EDITOR=vim to ~/.bashrc. How can the user apply the change to the current Bash session without opening a new terminal?

  41. Question 41 of 60 Introduction to Bash scripting Hard

    A script named setup.sh contains cd /tmp and export MODE=test. Which invocation makes both changes affect the current interactive Bash session?

  42. Question 42 of 60 Bash script structure Hard

    An executable script has a blank line before #!/usr/bin/env bash. Which change ensures the operating system recognizes and uses the intended interpreter when the script is run as ./tool?

  43. Question 43 of 60 Hello World Hard

    A variable may contain percent signs, backslashes, spaces, or -n. Which command reliably prints its value followed by exactly one newline?

  44. Question 44 of 60 Variables Hard

    What does payload=$(printf 'A\n\n'); printf '<%s>\n' "$payload" print?

  45. Question 45 of 60 User input Hard

    A user enters two leading spaces, a\b, and two trailing spaces. Which command stores all those characters unchanged in value?

  46. Question 46 of 60 Comments Hard

    Consider : <<'BLOCK', followed by lines containing $HOME and $(touch marker), and then a line containing only BLOCK. What happens when Bash executes this construct?

  47. Question 47 of 60 Arguments Hard

    After set -- "a b" "" c, what is printed by for x in "$@"; do printf '[%s]' "$x"; done?

  48. Question 48 of 60 Arrays Hard

    Given a=([2]=x [5]=y); unset 'a[2]'; a+=(z), what does printf '%s|%s\n' "${!a[@]}" "${#a[@]}" print?

  49. Question 49 of 60 String slicing Hard

    With s=abcdef, which expansion produces de?

  50. Question 50 of 60 Conditional expressions (file, string, arithmetic) Hard

    p names a symbolic link whose target does not exist, s=abc, and n=08. Which condition succeeds without interpreting 08 as an invalid octal number?

  51. Question 51 of 60 Exit status Hard

    What is printed by set -o pipefail; false | (exit 3) | true; printf '%s\n' "$?"?

  52. Question 52 of 60 If-else statements Hard

    An existing file contains no line beginning with key=. Which branch runs in if result=$(grep -m1 '^key=' file); then echo found; else echo absent; fi?

  53. Question 53 of 60 Switch-case statements Hard

    What is printed by case foobar in foo*) printf generic ;; f??bar) printf specific ;; *bar) printf suffix ;; esac?

  54. Question 54 of 60 Loops (for, while, until) Hard

    What is printed by i=0; while (( i < 4 )); do ((i++)); (( i == 2 )) && continue; printf '%s' "$i"; done?

  55. Question 55 of 60 Break and continue statements Hard

    What is printed by for a in 1 2; do for b in x y z; do [[ $b == y ]] && break 2; printf '%s%s' "$a" "$b"; done; printf inner; done; printf end?

  56. Question 56 of 60 Functions Hard

    What is printed by x=global; g() { printf '%s\n' "$x"; }; f() { local x=outer; g; }; f in Bash?

  57. Question 57 of 60 Debugging Hard

    Which setup enables execution tracing and defers expansion of source file, line number, and function name until each trace line is emitted?

  58. Question 58 of 60 Shortcuts Hard

    With Bash Readline using the Emacs keymap, which shortcut opens the current command line in the editor configured by $VISUAL or $EDITOR, then executes the edited command when the editor closes?

  59. Question 59 of 60 Custom commands Hard

    A script has been installed as ~/.local/bin/report during the current Bash session. Which command sequence makes it directly executable by name and refreshes Bash's command-location cache?

  60. Question 60 of 60 Persistent changes Hard

    Which arrangement persistently defines alias ll='ls -alF' for both interactive login shells and interactive non-login Bash shells?

That's unit 3

Answer a few questions and your score shows up here.