Answer the question
In order to leave comments, you need to log in
How to get boxed output with line wrapping?
There is a script that displays system info
VAR=$(echo -e "$MEM\n$HDD\n$CPU")
echo "$VAR2"
Memory Usage: 277/1983MB (13.97%)
Disk Usage: 5/16GB (35%)
CPU Load: 0.00
banner() {
msg="# $* #"
edge=$(echo "$msg" | sed 's/./#/g')
echo "$edge"
echo "$msg"
echo "$edge"
}
banner $VAR
#############################################################################
# Memory Usage: 277/1983MB (13.97%) Disk Usage: 5/16GB (35%) CPU Load: 0.00 #
#############################################################################
Answer the question
In order to leave comments, you need to log in
I want to create a frame around the output, for this I use the function
msg="# $* #"
MEM="Memory Usage: 277/1983MB (13.97%)"
HDD="Disk Usage: 5/16GB (35%)"
CPU="CPU Load: 0.00"
VAR="$MEM\n$HDD\n$CPU"
banner() {
v="[email protected]"
x=$(echo -e "$v" |awk '{if(length>max)max=length}END{for(i=1;i<max+5;i++){printf "#"}}')
echo "$x"
echo -e "$v" |awk '{print "# "$0" #"}' |column -t -s: -o: |column -t -s'#' -o'#'
echo "$x"
}
banner "$VAR"
#####################################
# Memory Usage: 277/1983MB (13.97%) #
# Disk Usage : 5/16GB (35%) #
# CPU Load : 0.00 #
#####################################
MEM="Memory,277/1983MB,13.97%"
HDD="Disk,5/16GB,35%"
CPU="CPU,0.00,"
echo -e "$MEM\n$HDD\n$CPU" |csview -H --style Reinforced
┏────────┬────────────┬────────┓
│ Memory │ 277/1983MB │ 13.97% │
│ Disk │ 5/16GB │ 35% │
│ CPU │ 0.00 │ │
┗────────┴────────────┴────────┛
MEM="Memory Usage: 277/1983MB (13.97%)"
HDD="Disk Usage: 5/16GB (35%)"
CPU="CPU Load: 0.00"
banner() {
max=$(echo -e "$1"|awk '{if(length>max)max=length}END{printf max}')
echo -e "$1"|awk 'BEGIN{for(i=1;i<'$max'+4;i++){printf "#"};print "#"}{printf "# %'$max's #\n", $0}END{for(i=1;i<'$max'+4;i++){printf "#"};print "#"}'
}
banner "$MEM\n$HDD\n$CPU"
$ banner "$MEM\n$HDD\n$CPU"
#####################################
# Memory Usage: 277/1983MB (13.97%) #
# Disk Usage: 5/16GB (35%) #
# CPU Load: 0.00 #
#####################################
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question