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 10 MCQs Shell programming

CSE105 — Creative Engineering Workshop 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 Structure of Shell Scripts Easy

    Which line is conventionally placed at the very top of a shell script to specify the interpreter?

  2. Question 2 of 60 Creating and Executing Scripts Easy

    Which command makes a shell script named run.sh executable?

  3. Question 3 of 60 while loop Easy

    In a shell while loop, the loop body executes as long as the condition is:

  4. Question 4 of 60 for loop Easy

    What is the correct keyword used to end a for loop in shell scripting?

  5. Question 5 of 60 functions Easy

    Which is a valid way to define a function named greet in bash?

  6. Question 6 of 60 arrays Easy

    How do you access the first element of a bash array named arr?

  7. Question 7 of 60 Command-Line Arguments Easy

    Inside a shell script, which variable holds the first command-line argument?

  8. Question 8 of 60 Command-Line Arguments Easy

    Which special variable gives the total number of command-line arguments passed to a script?

  9. Question 9 of 60 Interactive Shell Scripts Easy

    Which command is used to read input from the user into a variable in a shell script?

  10. Question 10 of 60 if Easy

    Which keyword marks the end of an if statement in shell scripting?

  11. Question 11 of 60 if-else Easy

    Which keyword introduces the alternative block in a shell if-else statement?

  12. Question 12 of 60 nested if Easy

    What best describes a nested if in shell scripting?

  13. Question 13 of 60 test command and [] Easy

    In shell scripting, [ ] is equivalent to which command?

  14. Question 14 of 60 test command and [] Easy

    Which operator checks whether two integers are equal inside [ ]?

  15. Question 15 of 60 case Statement Easy

    Which keyword ends a case statement in shell scripting?

  16. Question 16 of 60 Operators in Shell Scripting Easy

    Which operator is used for string equality comparison in [ ]?

  17. Question 17 of 60 Operators in Shell Scripting Easy

    Which logical operator represents AND in shell conditional expressions?

  18. Question 18 of 60 arrays Easy

    Which syntax correctly declares an array in bash with three values?

  19. Question 19 of 60 functions Easy

    How is a value typically returned as output from a shell function to be captured by the caller?

  20. Question 20 of 60 while loop Easy

    Which keyword pair correctly begins and ends the body of a while loop in shell?

  21. Question 21 of 60 while loop Medium

    What will be the output of the following shell script?
    bash
    i=1
    while [ $i -le 3 ]
    do
    echo -n "$i "
    i=$((i+1))
    done

  22. Question 22 of 60 for loop Medium

    Which for loop correctly iterates over the numbers 1 to 5 using C-style syntax in Bash?

  23. Question 23 of 60 functions Medium

    In the script below, what does $1 refer to inside the function?
    bash
    greet() {
    echo "Hello $1"
    }
    greet World

  24. Question 24 of 60 arrays Medium

    Given arr=(apple banana cherry), what does ${#arr[@]} return?

  25. Question 25 of 60 arrays Medium

    How do you access the second element of a Bash array named colors?

  26. Question 26 of 60 Structure of Shell Scripts Medium

    What is the purpose of the line #!/bin/bash at the top of a shell script?

  27. Question 27 of 60 Creating and Executing Scripts Medium

    Which command makes a script file run.sh executable so it can be run with ./run.sh?

  28. Question 28 of 60 Interactive Shell Scripts Medium

    Which command reads a line of input from the user and stores it in a variable named name?

  29. Question 29 of 60 Command-Line Arguments Medium

    If a script is run as ./script.sh a b c, what value does $# hold?

  30. Question 30 of 60 Command-Line Arguments Medium

    What does $@ represent in a shell script?

  31. Question 31 of 60 Operators in Shell Scripting Medium

    Which operator is used to test whether two integers are equal in a test/[ ] expression?

  32. Question 32 of 60 Operators in Shell Scripting Medium

    What is the result of the arithmetic expansion echo $((7 % 3))?

  33. Question 33 of 60 if Medium

    What will the following script print?
    bash
    x=10
    if [ $x -gt 5 ]
    then
    echo "big"
    fi

  34. Question 34 of 60 if-else Medium

    Consider the script below. What is printed when the user enters 4?
    bash
    read n
    if [ $((n % 2)) -eq 0 ]
    then
    echo "even"
    else
    echo "odd"
    fi

  35. Question 35 of 60 nested if Medium

    In a nested if structure, when is the innermost block executed?

  36. Question 36 of 60 test command and [ ] Medium

    Which expression correctly checks whether the file data.txt exists and is a regular file?

  37. Question 37 of 60 test command and [ ] Medium

    Why is it important to put spaces inside the brackets, as in [ $a -lt $b ]?

  38. Question 38 of 60 case Statement Medium

    What will the following script output when fruit=banana?
    bash
    case $fruit in
    apple) echo "A";;
    banana) echo "B";;
    *) echo "other";;
    esac

  39. Question 39 of 60 case Statement Medium

    In a case statement, what role does the *) pattern serve?

  40. Question 40 of 60 functions Medium

    How can a shell function return an exit status that the caller can check with $??

  41. Question 41 of 60 Command-Line Arguments Hard

    In a Bash script, what is the difference between $@ and $* when both are used unquoted in a for loop iterating over arguments containing spaces?

  42. Question 42 of 60 test command and [] Hard

    What is the output of the following?
    bash
    x=""
    if [ $x = "a" ]; then echo yes; else echo no; fi

  43. Question 43 of 60 arrays Hard

    Given arr=(10 20 30 40), what does ${arr[@]:1:2} evaluate to?

  44. Question 44 of 60 Operators in Shell Scripting Hard

    What is the result of echo $(( 5 & 3 | 2 )) in Bash arithmetic?

  45. Question 45 of 60 for loop Hard

    What does this C-style loop print?
    bash
    for ((i=0; i<3; i++)); do
    echo -n "$i"
    done

  46. Question 46 of 60 functions Hard

    In the following, what does the script print?
    bash
    f() { local x=5; g; }
    g() { echo $x; }
    x=99
    f

  47. Question 47 of 60 while loop Hard

    Why might the following pipeline print 0 instead of the expected line count?
    bash
    count=0
    cat file.txt | while read line; do
    count=$((count+1))
    done
    echo $count

  48. Question 48 of 60 case Statement Hard

    Given x="apple", which pattern in a case statement matches?
    bash
    case $x in
    ae) echo one;;
    [aA]
    ) echo two;;
    *) echo three;;
    esac

  49. Question 49 of 60 if-else Hard

    What does the exit status of the if condition depend on here?
    bash
    if grep -q "foo" file.txt; then echo found; else echo missing; fi

  50. Question 50 of 60 nested if Hard

    What is printed?
    bash
    n=15
    if (( n % 3 == 0 )); then
    if (( n % 5 == 0 )); then echo FizzBuzz
    else echo Fizz; fi
    elif (( n % 5 == 0 )); then echo Buzz
    fi

  51. Question 51 of 60 Structure of Shell Scripts Hard

    Why is the shebang #!/usr/bin/env bash often preferred over #!/bin/bash?

  52. Question 52 of 60 arrays Hard

    Given declare -A m; m[x]=1; m[y]=2, what does echo ${#m[@]} output?

  53. Question 53 of 60 Operators in Shell Scripting Hard

    What does [[ "file.txt" == *.txt ]] && echo match output, and why?

  54. Question 54 of 60 Command-Line Arguments Hard

    After running ./script.sh a b c with shift 2 at the top, what does echo $1 $# print?

  55. Question 55 of 60 Interactive Shell Scripts Hard

    What is the effect of read -r -t 5 -p "Name: " name if the user types nothing for 6 seconds?

  56. Question 56 of 60 Creating and Executing Scripts Hard

    A script runs correctly with bash script.sh but fails with ./script.sh reporting Permission denied. What is the most likely cause?

  57. Question 57 of 60 functions Hard

    What does this script output?
    bash
    compute() { return 7; }
    compute
    echo $?

  58. Question 58 of 60 while loop Hard

    What does the following print?
    bash
    i=5
    while (( i-- )); do
    echo -n "$i "
    done

  59. Question 59 of 60 test command and [] Hard

    Which comparison correctly tests whether the integer in $n is greater than 10 in a POSIX [ ] test?

  60. Question 60 of 60 if Hard

    What is the behavior of if [ -n "$var" ] && [ -f "$var" ]; then echo ok; fi?

That's unit 10

Answer a few questions and your score shows up here.