I would like to write a small reminder that will be displayed on my console. I have found this link, But I don't know if there is a simpler way to write and display my document with colors.

My idea is to create a document cmd_info.txt. then creates a shortcut cmd_remaind that launches printf' %b\n'"$ (cat path_to_cmd_info.txt)".

I was looking for a display of this style in the Terminal. Title in green color, cmd in yellow and info in white.

Title 1

cmd1 info cnd2 info

Title 2

cmd1 info cnd2 info


Not really; such coloring is entirely dependent on the capabilities of your terminal, and bash's only role is to output the correct bytes for the terminal to read.

That said, and because coloring is terminal-specific, you can use tput to automatically output the correct bytes for your current terminal.

green=$(tput setaf 2)
yellow=$(tput setaf 3)
white=$(tput setaf 7)
default=$(tput sgr0)
echo "${green}Title 1$(default)"
echo "${yellow}cmd1${default}        ${yellow}info${default}"
echo "${yellow}cmd2${default}        ${yellow}info${default}"

Note that foreground colors 2, 3, and 7 are abstract, in that there is no guaranteed that they are actually green, yellow, and white, respectively. Those are the conventional colors, but a terminal emulator can be configured to use different colors for each abstract slot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.