我試圖格式化與外殼printf
一個字符串,我會得到一個文件輸入字符串,有特殊字符,如%,',"",,\user, \tan
等使用printf如何在shell腳本中轉義特殊字符?
如何逃避特殊字符的輸入字符串?
如
#!/bin/bash
#
string='';
function GET_LINES() {
string+="The path to K:\Users\ca, this is good";
string+="\n";
string+="The second line";
string+="\t";
string+="123"
string+="\n";
string+="It also has to be 100% nice than %99";
printf "$string";
}
GET_LINES;
我預計這將在我要像
The path to K:\Users\ca, this is good
The second line 123
It also has to be 100% nice than %99
格式打印,但它給人意外出局放
./script: line 14: printf: missing unicode digit for \U
The path to K:\Users\ca, this is good
The second line 123
./script: line 14: printf: `%99': missing format character
It also has to be 100ice than
那麼,如何擺脫打印時的特殊字符。 echo -e
也有問題。
的''%中的一個參數是可能性就是爲什麼你不應該在第一個參數'printf'擴大的參數。 – chepner 2014-09-21 16:33:33