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)
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!
Get Answers For Free
Most questions answered within 1 hours.