
從腳本執行時如何讓 printf 輸出十六進位字元?
假設我在提示符號處輸入 printf "\x41\x42"我得到的輸出
AB%
但是,如果我有一個包含該行的腳本,即 cat test.sh
產生
printf "\x41\x42"
但是執行腳本./test.sh產生
\x41\x42%
如何讓腳本產生與 shell 提示符號相同的結果?
答案1
嘗試使用外部printf
實用程式:
/usr/bin/printf "\x41\x42"
您可能有一個bash
shell,但作為互動式 shell, whilesh
連結到dash
.
dash
內建函數不printf
知道\xNN
,因此您必須使用八進位值 ,\0NN
來代替。
內建bash
確實printf
知道\xNN