For me it prints out right aligned. To left align it use %-, for example:
function main () { main_header printf "%-20s\n" "${YELLOW}Welcome ${USER}! Please select an option:" printf "%-60s\n" "${GREEN}[1] ${YELLOW}Install new sources.list" printf "%-60s\n" "${GREEN}[2] ${YELLOW}Update sources.list" printf "%-60s\n" "${GREEN}[3] ${YELLOW}Edit sources.list" printf "%-60s\n" "${GREEN}[4] ${YELLOW}Reset sources.list" }
This prints
Welcome ! Please select an option: [1] Install new sources.list [2] Update sources.list [3] Edit sources.list [4] Reset sources.list
(Excluding an error message about main_header: command not found)
To align subsequent lines under "Please", determine the length of indentation, create a variable with a format string that indents by that length and use that format string in printf statements of lines to be indented. The trick with the format string is it first writes an empty string to get the indentation equal to the field width, then it writes the string you want on the same line. For example,
indentString="${YELLOW}Welcome ${USER}! " indentLength=${#indentString} indentFormat="%${indentLength}s%s\n" printf "$indentFormat" "" "${GREEN}[1] ${YELLOW}Install new sources.list"
Putting this in main() it becomes:
function main () { indentString="${YELLOW}Welcome ${USER}! " indentLength=${#indentString} indentFormat="%${indentLength}s%s\n" main_header printf "%-20s\n" "${YELLOW}Welcome ${USER}! Please select an option:" printf "$indentFormat" "" "${GREEN}[1] ${YELLOW}Install new sources.list" printf "$indentFormat" "" "${GREEN}[2] ${YELLOW}Update sources.list" printf "$indentFormat" "" "${GREEN}[3] ${YELLOW}Edit sources.list" printf "$indentFormat" "" "${GREEN}[4] ${YELLOW}Reset sources.list" }
which prints:
Welcome training! Please select an option: [1] Install new sources.list [2] Update sources.list [3] Edit sources.list [4] Reset sources.list