Reputation: 1834
I have a variable that holds a number, using a shell script how can I convert the number to asterisk characters, for example 5 would be converted to *****
, 2 would be converted to **
Upvotes: 1
Views: 378
Reputation: 185219
Try doing this :
$ echo "azerty5qwerty5" | perl -pe 's/5/sprintf "%s", "," x $&/ge'
azerty,,,,,qwerty,,,,,
Upvotes: 0
Reputation: 17848
On simple solution is to use perl:
VAR=5
perl -e "print '*' x $VAR"
other solution is to use seq
:
VAR=5
for i in `seq $VAR` ; do echo -n '*' ; done
Upvotes: 1