Question

In: Computer Science

In shell script what is the reason this statement is not working? x=7 y=13 while [...

In shell script what is the reason this statement is not working?

x=7

y=13

while [ $x -le $y ]

do

echo $x

x=x+2

done

why on while statement it has error?

2.x=7

y=13

while [$x \< $y ]

do

echo $x

let x=x+2

done

what does it mean \< ? and give me the reason how this statement works

Solutions

Expert Solution

Question 1:

Issue Description:

if you run the given script, you ll get an error "Integer expression expected"

Answer: It is because of bad arithmetic expansion. you have to use $ and the expression should be inside double brackets $((expression))

This program assigns x  with 7 and y with 13 initially. x is incremented by two for each iteration and prints x value until x exceeds y i.e, 13.

The script should be as follows:

x=7

y=13

while [ $x -le $y ]

do

echo $x

x=$((x+2))

done

Sample Output:

Question 2: what does it mean \< ? and give me the reason how this statement works

Answer: There is no such operator \< in shell scripting. If you run the script with '\<', you ll get an error. See the output below,

you have to use the below operators as appropriate.

  • -le =>  Checks if the value of left operand is less than or equal to the value of right operand; if yes, then the condition becomes true.
  • -ge  => Checks if the value of left operand is greater than or equal to the value of right operand; if yes, then the condition becomes true.
  • -lt => Checks if the value of left operand is less than the value of right operand; if yes, then the condition becomes true.
  • -gt => Checks if the value of left operand is greater than the value of right operand; if yes, then the condition becomes true.
  • -ne => Checks if the value of two operands are equal or not; if values are not equal, then the condition becomes true.
  • -eq => Checks if the value of two operands are equal or not; if yes, then the condition becomes true.

I have replaced the operator \< by -le, see the script and output below.

x=7

y=13

while [ $x -le $y ]

do

echo $x

let x=x+2

done

Sample output:


Related Solutions

Design two shell programs working on Linux (Ubuntu) Design a shell script program, 1) reading given...
Design two shell programs working on Linux (Ubuntu) Design a shell script program, 1) reading given only two integer numbers from command line arguments and computing their multiplication. If two integer numbers are not given, print “Wrong Input” on your screen. Note that, the number of arguments is known when the script runs. Take a screenshot showing your shell program and its execution step. Design a shell program to remove all the shell programming files ending with sh on your...
Write the following Python script: Problem Statement A string X is an anagram of string Y...
Write the following Python script: Problem Statement A string X is an anagram of string Y if X can be obtained by arranging all characters of Y in some order, without removing any characters and without adding new characters. For example, each of the strings "baba", "abab", "aabb" and "abba" is an anagram of "aabb", and strings "aaab", "aab" and "aabc" are not anagrams of "aabb". A set of strings is anagram-free if it contains no pair of strings which...
U=U(X,Y)= 10X^0.9 * Y^0.1 the customer more likes X or Y? And what is the reason...
U=U(X,Y)= 10X^0.9 * Y^0.1 the customer more likes X or Y? And what is the reason for your answer? Thank you:) (1) calculate the MUx and MUy (2) the customer more likes x or y? (3) what is MRSxy
x 3, 4, 5, 7, 8 y 3, 7, 6, 13, 14 (a) Find the estimates...
x 3, 4, 5, 7, 8 y 3, 7, 6, 13, 14 (a) Find the estimates of Bo and B1. Bo=bo= _____ (Round to three decimal places as needed.) B1=b1= ______(Round to four decimal places as needed.) (b) Compute the standard error the point estimate for se= ____ (c) Assuming the residuals are normally distributed, determine Sb1=____ (Round to four decimal places as needed.) (d) Assuming the residuals are normally distributed, test HoB1=0 versus H1:B1/=0 at the a=0.05 level of...
What is the dominant color with these x and y values? x=7/15, y= 7/15 (z= 1/15...
What is the dominant color with these x and y values? x=7/15, y= 7/15 (z= 1/15 of course) Select one: a. Reddish green b. Greenish blue c. Violet d. Yellow
Write a script that will first initialize a string variable that will store x and y...
Write a script that will first initialize a string variable that will store x and y coordinates of a point in the form ‘x 3.1 y 6.4’. Then, use string manipulating functions to extract the coordinates and plot them. ANS % create a string variable of the form 'x 3.1 y 6.4' % extract the x and y coordinates and plot str = 'x 2.3 y 4.5'; [letter rest] = strtok(str); [x rest] = strtok(rest); [letter rest] = strtok(rest); y...
find y'' y=x^6/7+3x
find y'' y=x^6/7+3x
Element A has a valence shell configuration of ns2np4 while Element B has a valence 7...
Element A has a valence shell configuration of ns2np4 while Element B has a valence 7 shell configuration of ns2np5 where n = energy level. Choose all of the following statements that are true regarding these elements assuming they are on the same period? i. Element A is less electronegative then element B ii. Element B has a lower first ionization energy then element A iii. Element A has a more negative electron affinity then element B iv. The atomic...
Promotional expenses(x) Sales(y 7 12 10 14 9 13 4 5 11 15 5 7 3...
Promotional expenses(x) Sales(y 7 12 10 14 9 13 4 5 11 15 5 7 3 4 a) draw the scatter plot and draw the line of best fit b) Calculate and interpret the correlation between promotional expenses and sales C) Calculate the regression equation( calculate the slope and intercept of the regression line d)Interpret the slop coefficient of regression equation e)Using the regression equation calculate the sales volume with respect to promotional expense of 4. f) Obtain the coefficient...
What is a working set? What is the first line of every bash script? What is...
What is a working set? What is the first line of every bash script? What is the permission string (RWXRWXRWX format) of the number 311 What is the base directory of a file system called on windows, and on linux What does the term 'super user' mean in terms of operating systems
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT