Question

Write a script to display numbers from 1 to n, where n is an integer provided...

Write a script to display numbers from 1 to n, where n is an integer provided by users (if not, default to 10). Hint: use “read” command to accept user input.

a) Display the source code in an editor (#4-9)

b) Execute your script in the terminal, and display the command and the result (#4-10)

Homework Answers

Answer #1

You can use a for loop to print the elements on console.

Have a look at the below script. I have put comments wherever required for better understanding. You can save this script.

echo "Enter the number: "
# Read the user input
read n
# run a for loop from 1 to n
for i in $(seq 1 $n);
do 
  # display the numbers
  echo "Number: $i"
done

Happy Learning!

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Create x empty files in a given directory (x is a number), following a naming format...
Create x empty files in a given directory (x is a number), following a naming format like this: myfile1, myfile2, etc. Ask the user to enter the first part file name and the number of files he/she wants to create. Hint: you may use the “touch” command to quickly create empty files. Take two screenshots: a) Display the source code in an editor (#4-13) b) Execute your script in the terminal, and display the command and the result (#4-14)
Write a program in C++ coding that asks the user to input an integer between 25...
Write a program in C++ coding that asks the user to input an integer between 25 and 50, inclusive. Utilize a WHILE loop to test for INVALID input. If the input is INVALID, the loop will repeat, and ask the user to try again. The pseudocode looks like this: Prompt user to input an integer between 25 and 50 Accept the input from the user Test for invalid input (HINT: use a while loop and the OR operator with 2...
Write a program that asks the user to input an integer between 25 and 50, inclusive....
Write a program that asks the user to input an integer between 25 and 50, inclusive. Utilize a WHILE loop to test for INVALID input. If the input is INVALID, the loop will repeat, and ask the user to try again. The pseudocode looks like this: Prompt user to input an integer between 25 and 50 Accept the input from the user Test for invalid input (HINT: use a while loop and the OR operator with 2 relational expressions. You...
1- Create a new script that is called HW9.m and save it. The script will do...
1- Create a new script that is called HW9.m and save it. The script will do the following. Test your code for each of the cases and upload your script as a .m file. [15 points] a. Create a random integer numbers that goes from 0 to 5 and assign it to a variable y using rand and round commands. Hint: Note that rand function only creates random number between 0 and 1. You need to scale the values to...
Lottery The lottery game matches three different integer numbers between 1 and 10. Winning depends on...
Lottery The lottery game matches three different integer numbers between 1 and 10. Winning depends on how many matching numbers are provided by a player. The player provides three different integers between 1 and 10. If there is a match of all 3 numbers, the winning $ 1000. If there is a match with 2 numbers, the winning $ 10. If there is a match with 1 number, the winning $ 1. With no match, the winning is $0. Write...
Save your select statements as a script. Place the semicolon at the end of each SQL...
Save your select statements as a script. Place the semicolon at the end of each SQL statement. Please number your select statements from 1 to 8 in your script and comment out each number. Include your name and student number as a comment at the top of your script. The name of the script has to be Assignment1_JohnSmith. Instead of JohnSmith use your First Name and Last Name. Upload your script trough Blackboard. Use SQL Developer to create the My...
Write a function called TaylorSin.m that takes as input an array x, and positive integer N,...
Write a function called TaylorSin.m that takes as input an array x, and positive integer N, and returns the Nth Taylor polynomial approximation of sin(x), centered at a = 0. The first line of your code should read function s = TaylorSin(x,N) HINT: in computing k!, use kfact = k*(k-1)*kfact since you are counting by 2
1) Write a java programming using a while loop where you will add numbers and when...
1) Write a java programming using a while loop where you will add numbers and when you press number 0 it will add all your numbers and display the results. Use Scanner object. Steps: 1) Declare variables integer called sum which is equal to zero   2) Declare Scanner object   3) Declare while condition where is true   4) Inside of that condition prompt the user to enter the numbers   5) Declare variable integer called number and input the number statement   6)...
(EXCEL VBA)Write a program for a beauty store that uses an InputBox to ask the guest...
(EXCEL VBA)Write a program for a beauty store that uses an InputBox to ask the guest for a membership code. Embed this in a Do loop so that the user has to keep trying until the result is a valid membership code that starts with “Beauty” (case insensitive) and is followed by 4 digits with the final digit equal to either 6 or 8. Then use a message box to display the input promotion code and inform the user that...
Written in MASM Assembly Problem Definition: Write a program to calculate Fibonacci numbers. • Display the...
Written in MASM Assembly Problem Definition: Write a program to calculate Fibonacci numbers. • Display the program title and programmer’s name. Then get the user’s name, and greet the user. • Prompt the user to enter the number of Fibonacci terms to be displayed. Advise the user to enter an integer in the range [1 .. 46]. • Get and validate the user input (n). • Calculate and display all of the Fibonacci numbers up to and including the nth...