Use bash script to read numbers
bash, linux
Solution
Let's see what you already have. Your `for` loop does 10 iterations of a `read` command, and `read` appears only once in the script. You also append (`>>`) your output to the file `XYZ`.
You shouldn't use the same variable for loop counter and reading the input, though. And the sequence could be shortened to `{0..9}`.
What you're still missing is a condition to check that the user input actually is an integer. And you're probably supposed to output the value you read, not the string `"0,1,2,3,4,5,6,7,8,9"`.
On a more general note, you may find the following guides helpful with learning `bash`:
- Bash Guide for Beginners
- Advanced Bash Scripting Guide
Problem
Write a bash script that will read 10 integers from users and append the output to a file ‘XYZ’. You are not allowed to use the ‘read’ statement more than once in the script. ``` #! /bin/bash for i in {0,1,2,3,4,5,6,7,8,9} do read "i" echo "0,1,2,3,4,5,6,7,8,9" >> XYZ done ``` I am a student just bengin to learn this, I feel it is difficult, could you give me some suggestions? I think this should have many problems. Thank you very much.