この記事は約5分27秒で読むことができます。

escape sequence play


#!/bin/bash


## color code const
readonly C_GREEN=32;
readonly C_YELLOW=33;
readonly C_BLUE=34;
readonly C_MAGENTA=35;
readonly C_CYAN=36;
readonly C_L_RED=91;
readonly C_L_GREEN=92;
readonly C_L_YELLOW=93;
readonly C_L_BLUE=94;
readonly C_L_MAGENTA=95;
readonly C_L_CYAN=96;

pre_color=$PS1

function f_c()
{
printf "\033[${1}m${2}\033[${1}m\n";
}

echo 'please input'
echo '1:GREEN 2:YELLOW 3:BLUE 4:MAGENTA 5:CYAN 6:L_RED 7:L_GREEN 8:L_YELLOW 9:L_BLUE 10:L_MAGENTA 11:L_CYAN'

read num

case "$num" in
1)
color=${C_GREEN}
f_c ${color} "#########################"
f_c ${color} "||     hello world!    ||"
f_c ${color} "#########################"
;;
2)
color=${C_YELLOW}
f_c ${color} "#########################"
f_c ${color} "||     hello world!    ||"
f_c ${color} "#########################"
;;
3)
color=${C_BLUE}
f_c ${color} "#########################"
f_c ${color} "||     hello world!    ||"
f_c ${color} "#########################"
;;
4)
color=${C_MAGENTA}
f_c ${color} "#########################"
f_c ${color} "||     hello world!    ||"
f_c ${color} "#########################"
;;
5)
color=${C_CYAN}
f_c ${color} "#########################"
f_c ${color} "||     hello world!    ||"
f_c ${color} "#########################"
;;
6)
color=${C_L_RED}
f_c ${color} "#########################"
f_c ${color} "||     hello world!    ||"
f_c ${color} "#########################"
;;
7)
color=${C_L_GREEN}
f_c ${color} "#########################"
f_c ${color} "||     hello world!    ||"
f_c ${color} "#########################"
;;
8)
color=${C_L_YELLOW}
f_c ${color} "#########################"
f_c ${color} "||     hello world!    ||"
f_c ${color} "#########################"
;;
9)
color=${C_L_BLUE}
f_c ${color} "#########################"
f_c ${color} "||     hello world!    ||"
f_c ${color} "#########################"
;;
10)
color=${C_L_MAGENTA}
f_c ${color} "#########################"
f_c ${color} "||     hello world!    ||"
f_c ${color} "#########################"
;;
11)
color=${C_L_CYAN}
f_c ${color} "#########################"
f_c ${color} "||     hello world!    ||"
f_c ${color} "#########################"
;;
*)
;;
esac

f_c ${pre_color} ""
[oracle@centos7 lesson]$

Leave a Reply

Your email address will not be published. Required fields are marked *