0

Instead of multiple ${DOWN}'s is it possible to repeat x number of times?

readonly RED='\033[0;31m'
readonly NC='\033[0m' # No Color
readonly DOWN='\xE2\x96\xBC'
printf "%b%b%b%b look down %b%b%b%b\n" "${RED}" "${DOWN}" "${DOWN}" "${DOWN}" "${DOWN}" "${DOWN}" "${DOWN}" "${NC}"

▼▼▼ look down ▼▼▼
David Vasandani
  • 1,840
  • 8
  • 30
  • 53

1 Answers1

0

Use some command to repeat your down-string.

printf "%b%b%b%b look down %b%b%b%b\n" "${RED}" $(yes "${DOWN}" | head -6) "${NC}"
# or
printf "%b%b%b%b look down %b%b%b%b\n" "${RED}" $(for ((i=0;i<6;i++)); do echo "${DOWN}"; done) "${NC}"
# or
printf "%b%b%b%b look down %b%b%b%b\n" "${RED}" $(echo {1..6} | sed "s/[^ ]*/${DOWN}/g") "${NC}"

With above solutions you need to count the number of %b you use.
Perhaps you want something like

msg=" look down "
count=10
for ((i=0;i<${count};i++)); do
    msg="${DOWN}${msg}${DOWN}"
done
printf "%b%b%b\n" "${RED}" "${msg}" "${NC}"

Not printf "%b$msg%b\n" "${RED}" "${NC}", this goes wrong when msg has a %.

Walter A
  • 19,067
  • 2
  • 23
  • 43