Ana Sayfa / Linux / Bash Script / Color Script Output (Crossplatform)

Color Script Output (Crossplatform)

In the opening section of a bash script, it’s possible to define some variables that function as helpers to color or otherwise format the terminal output during the run of the script.

Different platforms use different character sequences to express color. However, there’s a utility called tput whichworks on all *nix systems and returns platform-specific terminal coloring strings via a consistent cross-platform API.

For example, to store the character sequence which turns the terminal text red or green:

red=$(tput setaf 1) green=$(tput setaf 2)

Or, to store the character sequence which resets the text to default appearance:

reset=$(tput sgr0)

Then, if the BASH script needed to show different colored outputs, this can be achieved with:

echo "${green}Success!${reset}"
echo "${red}Failure.${reset}"

Bunada Göz Atın

PHP Types

Type Comparison There are two types of comparison: loose comparison with == and strict comparison …

Bir yanıt yazın

E-posta adresiniz yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir