1

This:

dots=$(printf "%0.s." {1..10})

prints this:

.......... .

I'd like to know how to get printf in Bash to print .s up to a specific column position, let's say 30, where the start column will vary.

For example:

Add dots ....................

Add dots dots ...............

Add dots dots dots ..........

marshki
  • 607
  • 1
  • 4
  • 14

1 Answers1

0

In a shell

$ n=30
$ dots=$(printf "%.0s." $(seq $n))
$ echo "$dots"
..............................

So:

$ n=30
$ str='Add dots '
$ dots=$(printf "%.0s." $(seq $((n-${#str})) ))
$ echo "$str$dots"
Add dots .....................

And:

$ n=30; str='Add dots dots '; dots=$(printf "%.0s." $(seq $((n-${#str})) )); echo "$str$dots"
Add dots dots ................

In a function:

$ dots(){ printf "%s" "$2"; printf "%.0s." $( seq $(($1-${#2})) );echo; }
$ dots 30 "Add dots dots dots "
Add dots dots dots ...........

$ dots 40 "Add dots dots dots "
Add dots dots dots .....................

$ dots 33 "we hold these truths "
we hold these truths ............
  • `add dots` could just as well be 'we hold these truths` or 'I am sam` The point is that the start column will vary, but I always want to add '.` from the end of the string to the 30 column position. – marshki Sep 24 '18 at 01:49
  • @marshki Is the last command what you want? –  Sep 24 '18 at 01:52
  • Will test and let you know @Issac. – marshki Sep 25 '18 at 02:39