文本对齐居中 - shell 脚本 [英] Text alignment center - shell script

查看:84
本文介绍了文本对齐居中 - shell 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 shell 脚本创建一个简单的基于控制台的脚本.它将在我的 bash shell 上运行它是一个简单的基于菜单的驱动显示一些选项集.

I'm creating a simple console based script using shell script.It will be run on my bash shell Its a simple menu based driven display some set of options.

现在我想根据屏幕大小将文本居中对齐.如何在屏幕中心对齐文本?请帮助我

Now I want to do center align the text depending on the screen size. How do I align the text at center of the screen?Please assis me

推荐答案

我终于找到了解决方案:)

Finally I found the solution:)

COLUMNS=$(tput cols) 
title="Hello world!" 
printf "%*s\n" $(((${#title}+$COLUMNS)/2)) "$title"

这篇关于文本对齐居中 - shell 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆