Bash 腳本:十六進位

Bash 腳本:十六進位

我正在嘗試執行以下操作:

ch='\x21'
line="\x21"
len=50
for i in `seq 1 $len`
do
    line+="$ch"
done

而不是 50 個“!” (十六進位代碼 \x21)我得到 50 個 '\x21' 的列表。我怎樣才能在 bash 中做到這一點?

答案1

根據手冊頁,「形式的單字$'string'被特別對待」。因此,添加到$''組合中可能會有所幫助:

% bash
bash-3.2$ ch=$'\x21'; echo $ch$ch$ch
!!!
bash-3.2$ 

相關內容