function central_line() { #输入字符串长度 str_length=${#1} #echo ${str_length} #中心线长度 line_length=$(( (120-${str_length}) / 2 )) #echo ${line_length} line=`eval printf "=%0.s" {1..${line_length}}` #echo ${line} if ((str_length % 2)) ; then printf "${line} $1 ${line}\n" else printf "${line} $1 ${line}\n" fi } central_line "hello world" central_line "hello worldu" central_line "lina how are you now"
bash字符串中心化处理
转载
CENTRAL STRING
bash
本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Java-长字符串加密
加密:为你的长字符串提供最高级别的保护!!!
加密算法 JAVA -
bash字符串处理
bash字符串处理
字符串 bash -
BASH 中的字符串处理
得到长度CODE:%x="abcd"#方法一%expr length $x4# 方法二%echo ${#x}4
linux 职场 休闲 shell总结 -
Bash编程中的字符串处理
parameter, name, word, patternunset, null, abc
unset null abc -
Bash编程之数组和字符串处理
Bash编程之数组和字符串处理
linux bash -
bash字符串操作
子串的语法如下。${varname:offset:length}
bash 字符串 Bash 文件名