Any idea how I can still include empty space in a row using printf ie when the column variable is empty? For example:
printf $GREEN"################################ SOURCED ###############################"$RESET
printf $GREEN'%-1s%-15s%-60s%-1s%s\n' '#'$RESET ' REGION NAME:' $OS_REGION_NAME $GREEN'#'$RESET
printf $GREEN"########################################################################"$RESET
Basically I am creating a box with that shows sourced variables. Sometimes some of the fields are empty. The box shouldn't collapse on the right when this happens. I thought I had this down correctly with my column settings on that middle line, but apparently it ignores the width if the column is empty.
The output should look something like this:
################################ SOURCED ###############################
# AUTH URL: blah blah blah #
# REGION NAME: fcdnjcndkjcndkajcndkjcnklcnklsncklsnkcldnslc #
########################################################################
but it ends up looking like this
################################ SOURCED ###############################
# AUTH URL: blah blah blah #
# REGION NAME: fcdnjcndkjcndkajcndkjcnklcnklsncklsnkcldnslc #
########################################################################
SOLUTION
The solution was to put the variables inside double quotes. Such a simple fix...
printf $GREEN'%-1s%-15s%-55s%-1s%s\n' '#'$RESET ' REGION NAME:' "$OS_REGION_NAME" $GREEN'#'$RESET
NOTE
The $GREEN and $RESET was for coloring set in another part of script.
$OS_REGION_NAMEis empty then the variable value is the empty string and the command becomesprintf format '#reset' 'green#reset'i.e. you lose an argment.$GREENand$RESETvariables in the format string on the first and third lines and no reason to use double quotes on those lines either (not that they hurt anything either).greenandresetand not$GREENand$RESET. Use double quotes around any variable expansions.