linux - bash printf backslash then new line -


i trying create bash c header

#define xxxxx \   "id title\n" \    "1  developer\n" \  script   format="  \"%-4s  %-32s\\\n"  printf "$format" "id" "title\\n\"" >> $file  printf "$format" "1" "developer\\n\"" >> $file 

the result

"id    title\n"                        \n  "1     developer\n"                              \n 

when change format="%-4s %-32s \\ \n"

i get

"id    title\n"                           \  "1     developer\n"                       \  

and gcc start complain space after \

it seems \\ interpreted more once if there no space.

without using format="%-4s %-32s \\"

printf "$format" "id" "title\\n\"" >> $file  printf "\n" >> $file ... 

is there better way handle this?

use hexadecimal escape sequences:

format="%-4s %-32s \x5c\n" 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -