hash-example.sh

来自「BASH Shell 编程 经典教程 《高级SHELL脚本编程》中文版」· Shell 代码 · 共 61 行

SH
61
字号
#!/bin/bash# hash-example.sh: Colorizing text.# Author: Mariusz Gniazdowski <mgniazd-at-gmail.com>. Hash.lib      # Load the library of functions.hash_set colors red          "\033[0;31m"hash_set colors blue         "\033[0;34m"hash_set colors light_blue   "\033[1;34m"hash_set colors light_red    "\033[1;31m"hash_set colors cyan         "\033[0;36m"hash_set colors light_green  "\033[1;32m"hash_set colors light_gray   "\033[0;37m"hash_set colors green        "\033[0;32m"hash_set colors yellow       "\033[1;33m"hash_set colors light_purple "\033[1;35m"hash_set colors purple       "\033[0;35m"hash_set colors reset_color  "\033[0;00m"# $1 - keyname# $2 - valuetry_colors() {	echo -en "$2"	echo "This line is $1."}hash_foreach colors try_colorshash_echo colors reset_color -enecho -e '\nLet us overwrite some colors with yellow.\n'# It's hard to read yellow text on some terminals.hash_dup colors yellow   red light_green blue green light_gray cyanhash_foreach colors try_colorshash_echo colors reset_color -enecho -e '\nLet us delete them and try colors once more . . .\n'for i in red light_green blue green light_gray cyan; do	hash_unset colors $idonehash_foreach colors try_colorshash_echo colors reset_color -enhash_set other txt "Other examples . . ."hash_echo other txthash_get_into other txt textecho $texthash_set other my_fun try_colorshash_call other my_fun   purple "`hash_echo colors purple`"hash_echo colors reset_color -enecho; echo "Back to normal?"; echoexit $?#  On some terminals, the "light" colors print in bold,#  and end up looking darker than the normal ones.#  Why is this?

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?