将字符串转换来降低的Bash shell脚本的情况下, [英] Converting string to lower case in Bash shell scripting
本文介绍了将字符串转换来降低的Bash shell脚本的情况下,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有庆典转换字符串转换成小写的字符串?
例如,如果我有:
$ a =大家好
我想将其转换为:
$ a =大家好
解决方案
在各种不同的方法:
TR
$回声$ A| TR[:上:]''[:降低:]'
大家好
AWK
$回声$ A| AWK'{打印tolower的($ 0)}'
大家好
猛砸4.0
$回声$ {一} ,,
大家好
的Perl
$回声$ A| perl的-ne'打印LC
大家好
猛砸
LC(){
案$ 1
[A-Z])
N = $(printf的%d的$ 1)
N = $((N + 32))
printf的\\\\ $(printf的%O$ N)
ESAC
}
字=ABX
为((i = 0; I< $ {#字};我+ +))
做
CH =$ {字:$ I:1}
LC$ CH
DONE
Is there a way in bash to convert a string into a lower case string?
For example, if I have:
$a="Hi all"
I want to convert it to:
$a="hi all"
解决方案
The are various ways:
tr
$ echo "$a" | tr '[:upper:]' '[:lower:]'
hi all
AWK
$ echo "$a" | awk '{print tolower($0)}'
hi all
Bash 4.0
$ echo "${a,,}"
hi all
Perl
$ echo "$a" | perl -ne 'print lc'
hi all
Bash
lc(){
case "$1" in
[A-Z])
n=$(printf "%d" "'$1")
n=$((n+32))
printf \\$(printf "%o" "$n")
esac
}
word="ABX"
for((i=0;i<${#word};i++))
do
ch="${word:$i:1}"
lc "$ch"
done
这篇关于将字符串转换来降低的Bash shell脚本的情况下,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文