I am creating a bash script and would like to display a message with the correct aligned status (OK, Warning, Error, etc.) on the same line.
Without colors, alignment is ideal, but adding colors leads to incorrect correction of the aligned column in the next row.
#!/bin/bash log_msg() { RED=$(tput setaf 1) GREEN=$(tput setaf 2) NORMAL=$(tput sgr0) MSG="$1" let COL=$(tput cols)-${#MSG} echo -n $MSG printf "%${COL}s" "$GREEN[OK]$NORMAL" } log_msg "Hello World" exit;
source share