批处理实现文本内容居中显示 -shell
来源:互联网 发布:淘宝详情页html代码 编辑:程序博客网 时间:2024/05/15 19:38
批处理实现文本内容居中显示
题目如下
有一个文本a.txt
[Promise don’t come easy]
I should have known all along.
There was something wrong.
I just never read between the lines.
Then I woke up one day and found you on your way.
Leaving nothing but my heart behind.
What can I do to make it up to you.
Promises don’t come easy.
But tell me if there’s a way to bring you back home to stay.
Well I’d promises anything to you.
I’ve been walkin’ around with my head hanging down.
Wondrin’ what I’m gonna do.
‘Cause when you walked out that door.
要求,CMD原始窗口中,不调节窗口大小,居中显示文本内容。输出如下:
[Promise don't come easy] I should have known all along. There was something wrong. I just never read between the lines. Then I woke up one day and found you on your way. Leaving nothing but my heart behind. What can I do to make it up to you. Promises don't come easy. But tell me if there's a way to bring you back home to stay. Well I'd promises anything to you. I've been walkin' around with my head hanging down. Wondrin' what I'm gonna do. 'Cause when you walked out that door.
编写代码
#! /bin/bash# 输出具体数量空格后,输出内容# 参数1:空格数量# 参数2:内容function printll() { i=1 while [ ${i} -lt $1 ] do let i++ printf " " done echo $2}# 传入当前窗口列值# 参数1width=$1file=./a.txtwhile read linedo len=${#line} let w=(${width}-${len})/2 # 这里一定要加上引号,参数有空格会当做多个参数传入 printll ${w} "${line}"done < ${file}
执行命令
./test.sh ${COLUMNS}
ps:窗口列值:${COLUMNS},宽值:${LINES}
运行结果
参考文档
样式输出:http://blog.csdn.net/fdipzone/article/details/9993961
阅读全文
0 0
- 批处理实现文本内容居中显示 -shell
- 批处理实现文本内容横列变纵列-shell
- 文本/容器居中显示
- 文本居中显示
- 批处理实现两文本同行交替输出-shell
- div内容居中显示
- JTable内容居中显示
- 批处理中替换文本内容
- CSS3新方法,文本居中显示
- JTalbe中内容居中显示
- 使组件内容居中显示
- 设置input 内容居中显示
- 自定义AlertDialog内容居中显示
- 使用bat批处理替换文本中的内容
- 使用CSS让文本内容垂直居中
- Android UI 之居中绘制文本内容的正确方法——实现自定义一个TextView
- Android UI 之居中绘制文本内容的正确方法——实现自定义一个TextView
- Android UI 之居中绘制文本内容的正确方法——实现自定义一个TextView
- MacOS 终端指令查找本地ip地址以及写入Shell Script
- codeforces 448C 分治
- SGISTL源码探究-第二级配置器
- 解压.tar.xz结尾的文件
- 1对多业务,数据库水平切分架构一次搞定 | 架构师之路
- 批处理实现文本内容居中显示 -shell
- codeforces 846F Random Query
- Codeforces Round #432 (Div. 2) 总结
- 强力推荐!那些你不能错过的 GitHub 插件和工具
- 在Andorid中使用FFmpeg实现YUV解码为BMP
- 准确率,精确率,召回率以及f1
- NYOJ69
- 《UNIX网络编程 卷2》 笔记: 互斥锁与条件变量
- POJ_1015_Jury Compromise