Display colored words in a shell script (Linux)

Source: Internet
Author: User
Tags echo command

One, echo command (with parameter-e) cat color.sh#!/bin/bashecho -e  "\033[30m black \033[0m" echo -e   "\033[31m red \033[0m" echo -e  "\033[32m green \033[0m" echo -e  "\ 033[33m yellow \033[0m "echo -e " \033[34m blue \033[0m "echo -e " \033[ 35m purple \033[0m "echo -e " \033[36m cyan \033[0m "echo -e " \033[37m  white \033[0m "Execution Result: Bash color.sh black  red  green  yellow   blue  purple  cyan  white  Second, printf command cat color2.sh#!/bin/ bashprintf  "\033[30m black \033[0m\n" printf  "\033[31m red \033[0m\n" printf  "\033[32m green \033[0m\n" printf  "\033[33m yellow \033[0m\n" printf  "\033[34m  blue \033[0m\n "printf " \033[35m purple \033[0m\n "printf " \033[36m cyan  \033[0m\n "printf "\033[37m white \033[0m\n "Execution Results:bash color2.sh black  red  green   yellow  blue  purple  cyan  white three, use variable cat color3.sh#!/bin/ Bashblackcolor= ' \e[1;30m ' redcolor= ' \e[1;31m ' greencolor= ' \e[1;32m "yellowcolor= ' \e[1;33m ' bluecolor= ' \E[1;34m ' Purplecolor= ' \e[1;35m ' cyancolor= ' \e[1;36m ' whitecolor= ' \e[1;37m ' echo -e  ' ${blackcolor}black ' echo  -e  "${redcolor}red" echo -e  "${greencolor}green" echo -e  "${yellowcolor}yellow" echo -e  "${bluecolor}blue" echo -e  "${purplecolor}purple" echo -e  "${cyancolor} Cyan "echo -e " ${whitecolor}white "execution Result: Bash color3.shblackredgreenyellowbluepurplecyanwhite four, system function cat color4.sh#!/bin/bashblackcolor= "echo -en \\033[1;30m" redcolor= "echo -en \\033 [1;31m "greencolor=" echo -en \\033[1;32m "yellowcolor=" echo -en \\033[1;33m "bluecolor=" Echo  -en \\033[1;34m "PuRplecolor= "echo -en \\033[1;35m" cyancolor= "echo -en \\033[1;36m" whitecolor= "Echo -en  \\033[1;37m "echo black && ${blackcolor}echo red && ${ Redcolor}echo green && ${greencolor}echo yellow && ${yellowcolor }echo blue && ${bluecolor}echo purple && ${purplecolor}echo  cyan && ${cyancolor}echo white && ${whitecolor} Execution Results:bash  Color4.shblackredgreenyellowbluepurplecyanwhite

This article is from the "7928217" blog, please be sure to keep this source http://7938217.blog.51cto.com/7928217/1651807

Display colored words in a shell script (Linux)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.