Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Box that won't change size 1

Status
Not open for further replies.

TSch

Technical User
Jul 12, 2001
557
DE
Hi folks,

forgive my language problems, but I have no idea how else to describe my problem ... ;-)

I think it's best to just show you what I want to do:

I'd like to draw a little ASCII box around some variable outputs. But it's supposed to have a constant size no matter hoe long the output is ...

e.G.

I have to servers:

1) sierra1 (=$SYS)
2) blackbird001 (=$SYS)

The text in the box is being constructed like this:

echo "# System: $sys #"

The First Output would look like this:

############################
# System: sierra1 #
############################

But if I change the server the output looks like this:

############################
# System: blackbird001 #
############################

But I want it to look like this without having to change it manually for each server I have:

############################
# System: blackbird001 #
############################

How can I do this ?

Regards
Thomas


 
Hello Thomas,

I am quite sure that there are some clever people out there who are able to compute and output the needed number of blanks or tabs in a one-line command;
but I prefer another approach.

You didn't tell us which shell you are using; if you have no objections to ksh, you could use typeset command:

typeset -L10 sys
(Put this once at the beginning of your script; you will have to play around with the number; I did not test it!)

and then:
echo "# System: $sys #"

hope this helps
 
Hi,

great :)

That's exactly what I was looking for !

Thanks a lot.

Regards
Thomas
 
You can also use "[tt]printf[/tt]". Something like...
Code:
sys=blackbird001

printf "############################\n"
printf "# System: %-16s #\n" $sys
printf "############################\n"
See the man page for printf for more info.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top