Question

In: Computer Science

* Show the output of the following BASH code: i=7 i=$((i-5)) if [ $i -eq 4...

* Show the output of the following BASH code:


i=7
i=$((i-5))
if [ $i -eq 4 ] # -eq is ==
then
        echo "Four"
elif [ $i -eq 2 ] then
        echo "Two"
else
        echo $i
fi

Solutions

Expert Solution

Output of the above BASH code is "Two"

Explanation:

In the program "i" value is 7 then $i = $((i-5)) that is 7-5=2

Then the value of $i=2

In the code the if condition is that "if $i = 4 , Then display "Four" "

"if $i=2, Then display "Two" otherwise display value of "$i"

Since the $i value is 2 , the program displays "Two" as output

This is the reason , the program displays "Two" as output.

Error in the code:

In the above code , at elif statement "then" must be in next line

otherwise program will display an error.

Correct code:

i=7
i=$((i-5))
if [ $i -eq 4 ] # -eq is ==
then
        echo "Four"
elif [ $i -eq 2 ]
then
        echo "Two"
else
        echo $i
fi

Screenshot of the running code and Output:


Related Solutions

Code the following in bash and run. Please show full code and don’t forget to comment...
Code the following in bash and run. Please show full code and don’t forget to comment your code. Make a code that takes any list of numbers and calculates and displays the mean, median and mode.
Bash scripting return output: Determine the output this code 1. #!/bin/bash Valid = true count=1 while...
Bash scripting return output: Determine the output this code 1. #!/bin/bash Valid = true count=1 while [ $valid ] do echo $count if [ $count -eq 5 ]; then break fi ((count++)) done 2. #!/bin/bash num=100 for x in $(seq 1 5) do temp=$((num+x)) if [ $temp -1e 103]; then echo $temp else echo "Too Big" fi done 3.#!/bin/bash num=5 for x in $(seq 1 5) do echo $((num*x)) done 4. #!/bin/bash for x in $(seq 1 10) do echo...
21. What is the output of the following segment of code if 7 is input by...
21. What is the output of the following segment of code if 7 is input by the user when asked to enter a number?____________ int num; int total = 0; cout << "Enter a number from 1 to 10: "; cin >> num; switch (num) { case 1: case 2: total = 5; case 3: total = 10; case 7: total = total + 3; case 8: total = total + 6; default: total = total + 4; } cout...
I have to finish the code given by my diff eq professor to analyze the lorenz...
I have to finish the code given by my diff eq professor to analyze the lorenz function at different initial conditions and different values for p. I am not sure how to input the lorenz function in the way the code is set up. Here is the code provided for matlab: function lorenz s = 10; b = 8/3; p = 0.15; y = @(t,x) [ ; ; ]; % you are responsible for entering the lorenz system here T...
Show the output of the following code. Assume the node is in the usual info-link form...
Show the output of the following code. Assume the node is in the usual info-link form with info of the type int. Also, list and ptr are reference variables of the type Node. list = new Node( ); list.info = 88; ptr = new Node( ); ptr.info = 41; ptr.link = null; list.link = ptr; ptr = new Node( ); ptr.info = 99; ptr.link = list; list = ptr; ptr = new Node( ); ptr.info = 19; ptr.link = list.link;...
fix this code in python and show me the output. do not change the code import...
fix this code in python and show me the output. do not change the code import random #variables and constants MAX_ROLLS = 5 MAX_DICE_VAL = 6 #declare a list of roll types ROLLS_TYPES = [ "Junk" , "Pair" , "3 of a kind" , "5 of a kind" ] #set this to the value MAX_ROLLS pdice = [0,0,0,0,0] cdice = [0,0,0,0,0] #set this to the value MAX_DICE_VAL pdice = [0,0,0,0,0,0] cdice = [0,0,0,0,0,0] #INPUT - get the dice rolls i...
Ex 1. Show the contents of the array of integers 5 7 4 9 8 5...
Ex 1. Show the contents of the array of integers 5 7 4 9 8 5 6 3 each time a selection sort changes it while sorting the array into ascending order. Initial array:   5 7 4 9 8 5 6 3 ANSWER (Hint there are 8 lines, Show Array after each selection and swap):
4.Translate the following C code to MIPS assembly code. Assume that the value of i is...
4.Translate the following C code to MIPS assembly code. Assume that the value of i is in register $t0, and $s0 holds the base address of the integer MemArray if (i > 10) MemArray[i] = 0; else MemArray[i] = -MemArray[i]; 6.Translate the following C code to MIPS assembly code. Use a minimum number of instructions. Assume that the values of a, b, i, and j are in registers $s0, $s1, $t0, and $t1, respectively. Also, assume that register $s2 holds...
A = [4, 5, 9] B = [-4, 5, -7] C = [2, -7, -8, 5]...
A = [4, 5, 9] B = [-4, 5, -7] C = [2, -7, -8, 5] D = [1, -9, 5, -3] E = [3, 3, -1] Uz = 1/|z| ^z d(X,Y) = (Rθ) d = diameter R = Radius θ = Theta Find a. Uc b. d (D, C) c. Let P = B + 3E, UP = d. A x B e. 3B x E f. C x D
I need to develop a VHDL code for a FPGA basys 3, 4 digit 7 segment...
I need to develop a VHDL code for a FPGA basys 3, 4 digit 7 segment display. So when binary 0, 1 ,and 2 are inputted the display says bad. When binary 3,4,5,6, the display says good.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT