shell中大寫小轉換

2022-05-07 09:09:13 字數 2080 閱讀 2049

用tr需要新增變數,用declare或typeset需要在變數賦值前或者賦值後單獨宣告,都有些麻煩

此方法為bash 4.0以後新增,bash 4.0 2023年發布

$ test="abcdef"

# 把變數中的第乙個字元換成大寫

$ echo $

abcdef

# 把變數中的所有小寫字母,全部替換為大寫

$ echo $

abcdef

# 把變數中的第乙個字元換成小寫

$ echo $

abcdef

# 把變數中的所有大寫字母,全部替換為小寫

$ echo $

abcdef

the are various ways:

$

echo

"$a" | tr '[:upper:]'

'[:lower:]'

hi all

$

echo

"$a" | awk ''

hi all

you may run into portability issues with the following examples:

$

echo

"$"hi all

$

echo

"$a" | sed -e 's/\(.*\)/\l\1/'

hi all

#this also works:

$sed -e 's/\(.*\)/\l\1/'

<<< "$a"

hi all

$

echo

"$a" | perl -ne 'print lc'

hi all

lc()

word="i love bash"

for((i=0;i<$;i++))

do ch="$"

lc"$ch"

done

此方法為bash 4.0以後新增,bash 4.0 2023年發布

$ test="abcdef"

# 把變數中的第乙個字元換成大寫

$ echo $

abcdef

# 把變數中的所有小寫字母,全部替換為大寫

$ echo $

abcdef

# 把變數中的第乙個字元換成小寫

$ echo $

abcdef

# 把變數中的所有大寫字母,全部替換為小寫

$ echo $

abcdef

the are various ways:

$

echo

"$a" | tr '[:upper:]'

'[:lower:]'

hi all

$

echo

"$a" | awk ''

hi all

you may run into portability issues with the following examples:

$

echo

"$"hi all

$

echo

"$a" | sed -e 's/\(.*\)/\l\1/'

hi all

#this also works:

$sed -e 's/\(.*\)/\l\1/'

<<< "$a"

hi all

$

echo

"$a" | perl -ne 'print lc'

hi all

lc()

word="i love bash"

for((i=0;i<$;i++))

do ch="$"

lc"$ch"

done

金額大寫轉換

use toy go object storedprocedure dbo l2u script date 03 19 2014 13 15 27 set ansi nulls on goset quoted identifier on goalter procedure dbo l2u n low...

oracle 金額大寫轉換

function convert money input number number return varchar2 is i pls integer snum varchar2 20 ltrim replace to char abs input number 9999999999999990.9...

Python金額大寫轉換

判斷是否包含小數點,還有判斷是否只包含小數點和數字的這邊沒寫出來 def is contain dot check str check str str check str for ch in check str if ch return true return false def digital t...