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...
Simple shell scripting Write a Bash shell script called strcount.sh that counts the number of occurances...
Simple shell scripting Write a Bash shell script called strcount.sh that counts the number of occurances of a given string within a file. The scripts takes two arguments: the name of the file to check and the string to count occurances of. If the file is not found (or not readable), the script should print the error message Cannot access file and exit with code -1. Otherwise, the script should print the number of occurances of the given string and...
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 a bash shell script using the for-loop construct that counts the number of files and...
write a bash shell script using the for-loop construct that counts the number of files and directories looping through the files in the directory name provided by the user on a prompt by the script and prints "TOO many files" is the count of files is larger than a random number it generates between 20 and 40
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...
Write a program in C++ that generates a random number between 1 and 10 and asks...
Write a program in C++ that generates a random number between 1 and 10 and asks the user to guess it. Your program should continue until the user guesses the correct number. With each guess the user makes the program tells the user if the guess is too high or too low. To generate a random number between 1 and 10 you need the following code: /* initialize random seed: */ srand (time(NULL)); /* generate secret number between 1 and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT