Linux World
Pages
Home
Programming
Computer Architecture
Tit Bits
Trouble Shoot
Kernel Related
Quizzes
Linux Tips
Follow @Linux_world
Search
Christmas bell on linux terminal
Run the following script to generate a bell on the linux terminal.
#!/bin/bash str_dwn() { rows=$1 s_start=$2 char=$4 str_st_row=$3 rows_end=$((str_st_row+rows)) for((i=str_st_row;i<rows_end;i++)) do tput cup $i $s_start printf "$char " done echo"" } backslash() { b_st_row=$1 b_st_cols=$2 b_char=$3 b_r_end=$((b_st_row + size )) for((p=b_st_row;p<b_r_end;p++)) do tput cup $p $b_st_cols printf "$b_char " ((b_st_cols++)) done echo"" } forward() { f_st_row=$1 f_st_cols=$2 f_char=$3 f_r_end=$((f_st_row + size)) for((i=f_st_row;i<f_r_end;i++)) do tput cup $i $f_st_cols printf "$f_char " ((f_st_cols--)) done echo"" } horizontal() { hrow=$2 hstart=$1 hcols=$3 char=$4 end=$((hstart + hcols)) for((i=hstart;i<=end;i++)) do tput cup $hrow $i printf "$char" done echo"" } gen_rand() { num1=$1 if [ $num1 -eq 0 ] then temp=$(($RANDOM % 2)) rand=$((temp + 2)) else temp=$(($RANDOM % 5)) rand=$((temp + num1)) fi } set_color(){ color=$RANDOM color=$((color%6)) tput setaf $color } cols=`tput cols` mid=$((cols/2)) start=$((mid-16)) echo "What character do you want to use" read char echo "Choose the size of the bell, enter a number" read size tput clear rows=5 begin_row=2 num_cols=6 set_color horizontal $start 5 $size "$char" forward 5 $start "$char" back_cols=$((start + $size)) backslash 5 $back_cols "$char" lower_bar_start_cols=$((start-size)) lower_bar_size=$((size*3)) lower_bar_start_row=$((5 + size)) horizontal $lower_bar_start_cols $lower_bar_start_row $lower_bar_size "$char" top_bell_cols=$((start + size/2)) tput cup 4 $top_bell_cols printf "O" bottom_bell_cols=$((lower_bar_start_cols + size + size/2)) bottom_bell_row=$((lower_bar_start_row + 1)) tput cup $bottom_bell_row $bottom_bell_cols printf "00" tput setaf 0 tput cup 20 0
Run the script as follows $ chmod 777 bell.sh $ ./bell.sh What character do you want to use * Choose the size of the bell, enter a number 10
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment