Question

In: Computer Science

Shell script program that asks a number between 5 to 9. If the input is not...

Shell script program that asks a number between 5 to 9. If the input is not between 5 and 9, display an error message and ask again.

                                    Output

                                        1

                                       22

                                      333

                                     4444

                                    55555

                                   666666

                                7777777

                                 88888888

                           999999999

Solutions

Expert Solution

Hey here is answer to your question.If you liked the answer feel free to upvote. Thanks

#!/bin/bash
echo "Enter a number : "
read rows
if [ "$rows" -ge 9 ]; then
   echo "Invalid number"
   exit
fi
if [ "$rows" -le 5 ]; then
   echo "Invalid number"
   exit
fi
number=1
for((i=1; i<=rows; i++))
do
for((j=1; j<=rows - i; j++))
do
echo -n " "
done
number=$i
k=1
for((j=1; j<=2*i - 1; j++))
do
if [ $j -lt $i ];
then
echo -n "$number "
  
elif [ $j -eq $i ];
then
echo -n "$number "
  
else
echo -n "$number "
  
fi
done
echo
done

this is a bash script run it using.

bash sccript_filename

Nm #!/bin/bash echo "Enter a number : " read rows if [ "$rows" -ge 9 ]; then echo "Invalid number" exit 4 + ONO Fi 14 16 if [ "$rows" -le 5 ]; then echo "Invalid number" exit fi number=1 for((i=1; i<=rows; i++)) do for((j=1; j<=rows - i; j++)) do echo - - - done number=$i k=1 for((j=1; j<=2*i - 1; j++)) do if [ $j -lt $i ]; then echo -n "$number" elif [ $j -eq $i ]; then echo -n "$number" else echo -n "$number" 33 35 done input Output Success #stdin #stdout Os 4292KB Enter a number : 1 2 2 2 33333 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6


Related Solutions

Write a complete shell script that first asks the user to enter a URL. The script...
Write a complete shell script that first asks the user to enter a URL. The script should read the URL into a variable named url. The shell script should then retrieve the file associated with the URL by using the curl command. The output of the curl command should be redirected to a file named html_file. The shell script should then use the grep command to search the file named html_file for the word manhattan. Finally, the shell script should...
C++. Write a program that generates a random number between 5 and 20 and asks the...
C++. Write a program that generates a random number between 5 and 20 and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display Too high. Try again. If the user’s guess is lower than the random number, the program should display Too low, Try again. The program should use a loop that repeats while keeping a count of the number of guesses the user makes until...
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 Java program that asks a user to input a letter, converts the user input to...
Write Java program that asks a user to input a letter, converts the user input to uppercase if the user types the letter in lowercase, and based on the letter the user the user enters, display a message showing the number that matches the letter entered. For letters A or B or C display 2 For letter D or E or F display 3 For letter G or H or I display 4 For letter J or K or L...
Write a program that generates a random number between 1 and 100 and asks the user...
Write a program that generates a random number between 1 and 100 and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display “Too high, try again.” If the user’s guess is lower than the random number, the program should display “Too low, try again.” The program should use a loop that repeats until the user correctly guesses the random number. Your program should also keep a...
Write a program using a Scanner that asks the user for a number n between 1...
Write a program using a Scanner that asks the user for a number n between 1 and 9 (inclusive). The program prints a triangle with 2n - 1 rows. The first row contains only the square of 1, and it is right-justified. The second row contains the square of 2 followed by the square of 1, and is right justified. Subsequent rows include the squares of 3, 2, and 1, and then 4, 3, 2 and 1, and so forth...
Write a program that generates a random number between 1 and 50 and asks the user...
Write a program that generates a random number between 1 and 50 and asks the user to guess it. As a hint, it tells the user how many divisors it has, (excluding 1 and the number itself). Each time the user makes a wrong guess, it displays "Wrong" and says if the guess was too low or too high, until the user gets it right, in which case it says "Right" and says how many trials it took to guess...
this lab, you will write a shell script, called compare_cols.sh. This program should Read a CSV...
this lab, you will write a shell script, called compare_cols.sh. This program should Read a CSV file from standard input (STDIN). Note that in general, CSV files may contain quoted fields with embedded newlines. But for this assignment you can assume that there are no fields with embedded newlines, and therefore each new line represents a new row of the CSV file. Print a single number (integer) to standard output (STDOUT): the count of the lines in the CSV file...
Write a bash shell script that takes exactly one argument, a file name. If the number...
Write a bash shell script that takes exactly one argument, a file name. If the number of arguments is more or less than one, print a usage message. If the argument is not a file name, print another message. For the given file, print on the screen its content.
MATLAB Write a script which asks the user of the program to provide an initial horizontal...
MATLAB Write a script which asks the user of the program to provide an initial horizontal position, initial vertical position, initial velocity, and angle. Create a time vector spanning from zero seconds to 100 seconds incremented at 0.01 seconds. Call the function that you created in the previous problem to calculate the trajectory and velocities of the projectile. Find the maximum height of the projectile and the time at which it reaches that point. Write a neat sentence stating what...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT