Skip to content

Instantly share code, notes, and snippets.

@classmember
Created October 10, 2017 18:29
Show Gist options
  • Select an option

  • Save classmember/a6cf1a0401a3386ca391b999a13113c2 to your computer and use it in GitHub Desktop.

Select an option

Save classmember/a6cf1a0401a3386ca391b999a13113c2 to your computer and use it in GitHub Desktop.
#!/bin/sh
# padding output using printf
# reference: https://stackoverflow.com/questions/4409399/padding-characters-in-printf#4410103
pad=$(printf '%0.1s' "-"{1..60})
padlength=40
string2='bbbbbbb'
for string1 in a aa aaaa aaaaaaaa; do
printf '%s' "$string1"
printf '%*.*s' 0 $((padlength - ${#string1} - ${#string2} )) "$pad"
printf '%s\n' "$string2"
string2=${string2:1}
done
# ========================================
# = output =
# ========================================
#
# a--------------------------------bbbbbbb
# aa--------------------------------bbbbbb
# aaaa-------------------------------bbbbb
# aaaaaaaa----------------------------bbbb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment