Knowee
Questions
Features
Study Tools

If I run the bash script below as ./myscript.sh -i what will be the output to terminal?#!/bin/bashOPTERR="Invalid option"if [[ $# -gt 0 ]]; then    while getopts "zpa" opt; do        case $opt in            z) echo "Apple";;            p) echo "Banana";;            a) echo "Orange";;            *) echo "$OPTERR" && exit 1;;        esac    donefiexit 0

Question

If I run the bash script below as ./myscript.sh -i what will be the output to terminal?#!/bin/bashOPTERR="Invalid option"if [[ # -gt 0 ]]; then    while getopts "zpa" opt; do        case opt in            z) echo "Apple";;            p) echo "Banana";;            a) echo "Orange";;            *) echo "$OPTERR" && exit 1;;        esac    donefiexit 0

🧐 Not the exact question you are looking for?Go ask a question

Solution 1

The output will be "Invalid option". This is because the script is designed to only accept the options "z", "p", and "a". When you run the script with the "-i" option, it doesn't match any of the specified options, so the script echoes the value of the variable OPTERR ("Invalid option") and then exits with a status of 1.

Solution 2

The output will be "Invalid option".

Here's the step by step explanation:

  1. The script is run with the -i option.
  2. The script checks if there are any arguments passed to it. In this case, there is one argument (-i).
  3. The script enters a while loop where it uses the getopts function to iterate over the options. The options it is looking for are z, p, and a.
  4. When it encounters the -i option, it doesn't match any of the specified options (z, p, a).
  5. Therefore, it goes to the *) case, which is the default case when no other cases match.
  6. It then echoes "Invalid option" to the terminal and exits the script with a status of 1.

This problem has been solved

Similar Questions

If I run the command ./scriptname.sh parameters 5 5 with the code below, what will the output to terminal be?Note: You response must be precisely what will be printed to the terminal to be marked correct.#!/bin/bashecho $(expr substr "$1" "$2" "$3")exit 0

When the script below is run as ./myscript.sh repdat.txt, what will be output to the terminal?Note: Be precise in your answer. It must be exactly what would appear in the terminal#!/bin/bashcat $1 | grep -v "^[0-9]\{2\}%" | wc -lexit 0NOTE: The repdat.txt file contains the following lines:Breach data for the report was compiled in March and April 2020 by an independent research company.Key survey findings from respondents were as follows:94% said attack volume has increased in the last 12 months, the survey found.96% said their business has suffered a security breach in the last 12 months.The average organization said they experienced 2 breaches during that time, the survey found.88% said attacks have become more sophisticated.96% said they plan to increase cyber defence spending in the coming year.OS vulnerabilities and third-party application attacks were the leading cause of breachesCompanies said they are using an average of 7 different breach prevention technologies.

If I run the bash script below as ./myscript.sh -i what will be the output to terminal?#!/bin/bashOPTERR="Invalid option"if [[ $# -gt 0 ]]; then    while getopts "zpa" opt; do        case $opt in            z) echo "Apple";;            p) echo "Banana";;            a) echo "Orange";;            *) echo "$OPTERR" && exit 1;;        esac    donefiexit 0

When the script below is run as ./myscript.sh -d 10,6 what will the output to terminal be?#!/bin/bashOPTERR="Invalid option"declare -a argsIFS=','if [[ $# -gt 0 ]]; thenwhile getopts "a:s:d:m:" opt; do        for arg in $OPTARG; do            args+=("$arg")        done        case $opt in            a) echo $( expr ${args[0]} + ${args[1]} );;            s) echo $( expr ${args[0]} - ${args[1]} );;            d) echo $( expr ${args[0]} / ${args[1]} );;            m) echo $( expr ${args[0]} \* ${args[1]} );;            *) echo "$OPTERR" && exit 1;;        esac    donefiIFS=" "exit 0

QUESTION: When the code below is run, what will be output to the terminal?#!/bin/bashstr='Book Title 1: <em>Think and Grow Rich</em> by Napoleon Hill'echo $str | sed 's/.*>.∗<.*/\1/'exit 0Group of answer choices<em></em>hink and Grow Ricby Napoleon HillThink and Grow Rich

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.