Wednesday, 7 August 2013

bash printf backslash then new line

bash printf backslash then new line

I am trying to create this from bash into a c header
define XXXXX \ "id title\n" \ "1 developer\n" \
the script is
FORMAT="%-4s %-32s \\n"
printf "$FORMAT" "id" "title" >> $FILE
printf "$FORMAT" "1" "Developer" >> $FILE
the result would be id title \n1 2e \n
when I change FORMAT="%-4s %-32s \ \n"
I get id title \ 1 Developer \ and gcc start to complain the extra space
after \
It seems that the \ would be interpreted more than once if there is no space.
without using FORMAT="%-4s %-32s \"
printf "$FORMAT" "id" "title" >> $FILE
printf "\n" >> $FILE ...
Is there any better way to handle this?

No comments:

Post a Comment