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...
Show the output of the following code segment. int count=0;                         for (int i=2; i <=...
Show the output of the following code segment. int count=0;                         for (int i=2; i <= 4; i++ ) {                                     StdOut.println(i);                                     for (int j=1; j <3; j++) {                                                 count++;                                                 StdOut.println(i +" " + j +" "+ count);                                     }                         } count i j I print 0 2 1 3 1 1 1 2 3 2 2 3 3 3 3 4 3 Show the output of the function call statements shown.             double x =...
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):
In C++, Complete the Code & Show the output. Schedule the following process using Shortest Job...
In C++, Complete the Code & Show the output. Schedule the following process using Shortest Job First Scheduling algorithm Porcress Burst time Arrival time 1 8 0 2 2 0 3 1 0 4 4 0 Compute the following and show the output a) Individual Waiting time & Turnaround time b) Average Waiting time & Turnaround time c) Display the Gantt chart (Order of Execution)    #include using namespace std; //structure for every process struct Process { int pid; //...
The output of the following code is "11 0" But I am not sure why, can...
The output of the following code is "11 0" But I am not sure why, can someone please explain to me clearly and concisely why this is the case? main(){ int n=1; if(fork()) wait(&n); else n=n+10; printf("%d\n", n); exit(0); }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT