Question

In: Computer Science

Linux Given a passed parameter to a script, request a number from the user and print...

Linux

Given a passed parameter to a script, request a number from the user and print the parameter as many times as that number.

Solutions

Expert Solution

Source Code with comments for your better understanding-

#!/bin/bash
  

#reading the value from the first positional parameter denoted by $1
parameter_read=$1

#readding number from the user
read -p "Please input a number: " numberinput

#printing out the number that was given by the user
echo "You have typed this number ${numberinput}"

#initializing a variable i with digit 1
i=1

#doing a while loop to start from the initialised value of variable i till the digit which was 
#given by the user
while [ "${i}" -le "${numberinput}" ]
do
        #printing out the parameter which was passed in the script
        echo "${parameter_read}"
                #incrementing the variable by adding plus 1
        i=`expr ${i} + 1 `

done

Create a script of your own choice and paste the abovecode in that script

Then call the script in this way (given below) from your command line terminal

sh scriptname parametervalue

where scriptname will be scriptname of your choice and parametervalue will be the parameter name of your choice

In our script I have passed hello as parameter and have given a digit 7 as input

So output will be hello which will be printed 7 times in separate lines

Screenshot-


Related Solutions

In Kali Linux Write a script that ask the user to enter an IP address and...
In Kali Linux Write a script that ask the user to enter an IP address and a port number, then use the provided entries from the user to perform a query on your local network and determine if the given port is open on the provide network. Need to submit solutions for both below. 1.A short report showing the functionality of your code 2. your bash script
how to write a cpp program that takes a number from a user, and print the...
how to write a cpp program that takes a number from a user, and print the sum of all numbers from one to that number on screen? using loop interation as basic as possible.
Linux Sign into your lab account Write a bash shell script that does the following: Print...
Linux Sign into your lab account Write a bash shell script that does the following: Print out a friendly welcome message Ask the user for the name of their favorite animal Grep that animal from a text file noises.txt Tell the user what that animal says (i.e. what noise does it make) If the animal does not exist ask the user what noise the animal makes Store that new information in noises.txt
write a script in ruby to automate user account creation in Linux using a CSV file....
write a script in ruby to automate user account creation in Linux using a CSV file. Username is a combination of first initial last initial of the first name and last name in the last name followed by the first initial last initial(Ex. Sam Smith = smithsm). If two or more employees had the same first and last name appends a number to the end of the username. After accounts are created write the first and last names along with...
write a java program that takes three numbers from the user and print the greatest number...
write a java program that takes three numbers from the user and print the greatest number (using if-statement). sample output: input the first number:35 input the second number:28 input the third number:87 the greatest number:87
WILL UPVOTE ANSWER! Modify the given code to accept two integers from the user and print...
WILL UPVOTE ANSWER! Modify the given code to accept two integers from the user and print one of the following messages - the 1st number is bigger - the 2nd number is bigger - two numbers are equal ###################################### .data str1 : .asciiz "enter the 1st integer " str2 : .asciiz "enter the 2nd integer " str3 : .asciiz "The 1st num is bigger" str4 : .asciiz "The 2nd num is bigger" str5 : .asciiz "Two numbers are equal" .text...
Using Python The script is to open a given file. The user is to be asked...
Using Python The script is to open a given file. The user is to be asked what the name of the file is. The script will then open the file for processing and when done, close that file. The script will produce an output file based on the name of the input file. The output file will have the same name as the input file except that it will begin with "Analysis-". This file will be opened and closed by...
print a menu so that the user can then order from that menu. The user will...
print a menu so that the user can then order from that menu. The user will enter each item they want until they are done with the order. At the end you will print the items the user ordered with their price and the total. Note: You will be storing your menu items (pizza, burger, hotdog, salad) and your prices (10, 7, 4, 8) in separate lists. Menu 0) pizza $10 1) burger $7 2) hotdog $4 3) salad $8...
Write a PowerShell script which will prompt user to enter the number of the day of...
Write a PowerShell script which will prompt user to enter the number of the day of the week (e.g. 1,2,3,4,5,6,7) and return the day of the week. (e.g. Sunday...etc.) (Hint: Sunday is the 1st day of the week).
Using Bash script, 1. Print the multiplication table upto 10 rows. Ask the user to enter...
Using Bash script, 1. Print the multiplication table upto 10 rows. Ask the user to enter a number. say user enters 10, your output should be : [srivatss@athena shell]> ./mult.sh I will be printing the multiplication table Please enter a number 10 1 x 10 = 10 2 x 10 = 20 3 x 10 = 30 4 x 10 = 40 5 x 10 = 50 6 x 10 = 60 7 x 10 = 70 8 x 10...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT