I am having a bash script which is something like following,
cat filename | while read line do read input; echo $input; done
but this is clearly not giving me the right output as when I do read in the while loop it tries to read from the file filename because of the possible I/O redirection.
Any other way of doing the same?
Use while Loop With User Input in JavaThe loop will continue to take user inputs till there is an input number that is not a member of the array. Let's try multiple inputs till the loop breaks. The loop will break when a number is entered which is not a member of the array. Run code here.
First Read the input number asking for the length of the list using the input() function and store these values into a list. After that, you can use the sum() function or Iterate each element in the list using for loop and sump up all.
Read from the controlling terminal device:
read input </dev/tty
more info: http://compgroups.net/comp.unix.shell/Fixing-stdin-inside-a-redirected-loop
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With