You're already using printf
in the true
branch of your if
statement, which supports formatted output. How about something like this, assuming $CS
contains the truth value of your "Found" vs "Not Found" condition:
printf "$color%-50s%s$RESET\n" "$url" "$status"
Where $color
is the ANSI code for the desired color, $RESET
is the ANSI code \e[0m
and $url
and $status
are the URL string and the [Found] or [Not Found] status strings, respectively.
Here's a full example. Note I've used sh
in the shebang, but this is fully compatible with bash syntax as well:
#!/bin/sh
BLUE="^[[0;34m"
RED="^[[0;31m"
RESET="^[[0m"
CS=0
for url in http://example.com/foo http://example.com/longer_address ; do
if [ $CS -eq 0 ]; then
color=$BLUE
status='[Found]'
else
color=$RED
status='[Not Found]'
fi
printf "$color%-50s%s$RESET\n" "$url" "$status"
CS=1 # Change truth condition for next test
done