I am trying to format a string with printf
in shell, i will get input string from a file , that have special characters like %,',"",,\user, \tan
etc.
How to escape the special characters that are in the input string ?
Eg
#!/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;
i am expecting this will print in the format i want like
The path to K:\Users\ca, this is good
The second line 123
It also has to be 100% nice than %99
But its giving unexpected out puts
./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
So how can i get rid of the special characters while printing.? echo -e
also has the issue.
Try
printf "%s\n" "$string"
See printf(1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With