r/programminghelp • u/GuitarMan_06 • Nov 08 '21
Other Linux Shell Script Multiplying String With Integer By Reading file
I am new on Linux and Shell programming. I've been trying to read a file which contains numbers. And I tried to multiply those numbers with "*". For example:
5
4
7
2
1
are numbers which contained in the txt file. Let's assume that the script file's name is program and the txt file's name is input. Program should run like:
>./program input
And output needs to be
*****
****
*******
**
*
And here is my code:
#!/bin/bash
filename = $1 #takes the file name from user as terminal argument
while read line; do echo -n "*";done #while loop reads the file line by line and prints asterisk
done<$filename
Well, in that code I need to multiply line and "*" but somehow I just could not find anything about it.
I would be really appreciated if you could help. Thanks for the attention.
2
u/ConstructedNewt MOD Nov 08 '21
https://stackoverflow.com/questions/169511/how-do-i-iterate-over-a-range-of-numbers-defined-by-variables-in-bash