- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Center text on the screen
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2003 11:31 AM
06-19-2003 11:31 AM
Does anyone have an example of an easy way to center
text messages on a terminal? I would like to easily center menu titles without having to count spaces.
Thanks in advance for any ideas,
Bob
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2003 11:37 AM
06-19-2003 11:37 AM
SolutionI ain't got one but it shouldn't be too difficult to whup one up.
#!/usr/bin/sh
centerit()
{
if [[ ${#} -lt 1 ]]
then
return 255
fi
XS=${1}
shift
while [[ ${#} -ge 1 ]]
do
XS="${XS} ${1}"
shift
done
XPOS=$((($(tput cols) - ${#XS}) / 2))
XI=0
while [[ ${XI} -lt ${XPOS} ]]
do
echo " \c"
XI=$((${XI} + 1))
done
echo "${XS}"
return 0
}
#example
centerit "This is a test"
# or
centerit This is a test
Note that this uses tput cols to get the screen width so it should work on any terminal.
If I didn't miss any typo's then this guy should also work if you quote the args (suggested) or not.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2003 11:37 AM
06-19-2003 11:37 AM
Re: Center text on the screen
Enjoy, have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2003 11:40 AM
06-19-2003 11:40 AM
Re: Center text on the screen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2003 11:44 AM
06-19-2003 11:44 AM
Re: Center text on the screen
Here's a crude example:
#!/usr/bin/sh
MSG="This message is centered!"
MSZ=${#MSG}
COL=`echo "(80-${MSZ})/2"|bc`
clear
tput cup 12 ${COL}
echo ${MSG}
tput cup 23 0
exit 0
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2003 12:10 PM
06-19-2003 12:10 PM
Re: Center text on the screen
Thanks,
Bob