Question

In: Computer Science

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 $x

done

5. line 1

line 2

line 3

line 4

line 5

head -n4 < data.txt > t1.txt

tail -n1 <t1.txt > out.txt

cat out.txt

Solutions

Expert Solution

NOTE:- I HAVE ATTACHED THE PROGRAM IN A SEQUENCE OF

1.THE CODE WITH SNIPPET

2.SCREENSHOTS OF THE OUTPUT

------ANSWER-------

CODE FOR PROGRAM 1 WITH OUTPUT

valid=true
count=1

while [ $valid ]

do

echo $count

if [ $count -eq 5 ];

then

break

fi

((count++))

done

valid=true
count=1

while [ $valid ]

do

echo $count

if [ $count -eq 5 ];

then

break

fi

((count++))

done

OUTPUT

CODE FOR PROGRAM 2

IN THE PROGRAM 2 THERE WAS 2 ERROR WHICH IS SOLVED

1. IN THE IF CONDITION IT IS -le NOT -1e

2. WE NEED TO PUT 103 IN SINGLE QUOTES '103' LIKE THIS IN THE IF CONDITION

I HAVE ALSO ATTACHED THE OUTPUT OF THE CORRECTED CODE WITH YOUR CODE ALSO.

num=100

for x in $(seq 1 5)

do

temp=$((num+x))

if [ $temp -le '103' ]; then

echo $temp

else

echo "Too Big"

fi

done

num=100

for x in $(seq 1 5)

do

temp=$((num+x))

if [ $temp -le '103' ]; then

echo $temp

else

echo "Too Big"

fi

done

OUTPUT OF CORRECTED CODE

OUTPUT OF YOUR CODE

CODE FOR PROGRAM 3

num=5

for x in $(seq 1 5)

do

echo $((num*x))

done

num=5

for x in $(seq 1 5)

do

echo $((num*x))

done

OUTPUT

CODE FOR PROGRAM 4

for x in $(seq 1 10)

do

echo $x

done

for x in $(seq 1 10)

do

echo $x

done

OUTPUT

CODE FOR PROGRAM 5

FOR PROGRAM 5 WE NEED TO FIRST OF ALL SAVE THE GIVEN DATA INTO A DATA.TXT FILE THEN AND THEN ONLY WE CAN EXECUTE IT.

head -n4 < data.txt > t1.txt

tail -n1 <t1.txt > out.txt

cat out.txt

head -n4 < data.txt > t1.txt

tail -n1 <t1.txt > out.txt

cat out.txt

OUTPUT

Note: If you have any queries then let me know in the comments. If you find it helpful then a Like would be appreciated.


Related Solutions

Consider the following code segment:    count = 1    while count <= 10:       print(count,...
Consider the following code segment:    count = 1    while count <= 10:       print(count, end=" ") Which of the following describes the error in this code? The loop control variable is not properly initialized. The comparison points the wrong way. The loop is infinite. The loop is off by 1. Does this code contain an error? If so, what line is the error on? 0: ans = input("Yes/No? ") 1: if ans == "Yes": 2: print("Confirmed!") 3: else...
Why is java programming better than bash scripting. Why should programmers write in java code ?...
Why is java programming better than bash scripting. Why should programmers write in java code ? Come up with situations where java is a better option.
Write the code to return the output in Rstudio. What is the code? Code: x <-...
Write the code to return the output in Rstudio. What is the code? Code: x <- c(28, 69, 5, 88, 19, 20) Output must be: [1] 4 2 1 6 5 3
* 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
Please code C# Convert the following for loop into a while loop: for(int count = 8;...
Please code C# Convert the following for loop into a while loop: for(int count = 8; count > 0; count--) { Console.WriteLine(count); }
Here are the tasks for this assignment: 1. Write a bash command line to determine if...
Here are the tasks for this assignment: 1. Write a bash command line to determine if the server 'syccuxfs01.pcc.edu' is reachable from the syccuxas01.pcc.edu server. 2. As you have read, TCP/IP messages are passed from one device to another until the message reaches its destination. Write a bash command line that will verify that no more than two (2) network devices are used to pass messages from the syccuxas01.pcc.edu server to the www.pcc.edu server. 3. Write a bash command line...
Answer the following true & false questions: The count property can be used to determine the...
Answer the following true & false questions: The count property can be used to determine the number of elements contained in an array. True False The Navigator object is commonly used to determine which type of Web browser is running. True False Since a browser window never displays more than one document object at one time, you can shorten references to objects contained within a document by omitting the word window from the object path. True False The setInterval( )...
True or False) The following code will output "I was true". bool isGreater(string s1, string s2)...
True or False) The following code will output "I was true". bool isGreater(string s1, string s2) { if(s1 > s2) { return true; } return false; } int main() { if(isGreater("before","back")) { cout << "I was true"; } else { cout << "I was false"; } return 0; }
Recall the is_hour(str) and is_minute(str) functions return True if the str contains valid hour and minute respectively
Recall the is_hour(str) and is_minute(str) functions return True if the str contains valid hour and minute respectively. That is, is_hour("03:65") would return True and is_minute("03:65") would return False.For each of the following expression, indicate whether short-circuit evaluation would occur. That is, the function call on the LHS of the logic operator would not actually be evaluated.ExpressionShort-circuit evaluationExpressionShort-circuit evaluationis_hour("03:65") and is_minute("03:65")--YesNois_hour("03:65") or is_minute("03:65"--YesNois_minute("03:65") and is_hour("03:65")--YesNois_minute("03:65") and is_hour("03:65")--YesNo
1. Determine if the following deduction rule is valid: p∨q ¬p _______ ∴ q 2. Determine...
1. Determine if the following deduction rule is valid: p∨q ¬p _______ ∴ q 2. Determine if the following is a valid deduction rule: (p∧q)→r ¬ p ∨ ¬ q ________ ∴     ¬r 3. Suppose p and q are (possibly molecular) propositional statements. Prove that p and q are logically equivalent if any only if p↔q is a tautology.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT