Reputation: 314
I have a git hook which calls a php file. The php file will produce an output (after running some Unit Tests). Te hook file is a sh file. The output from php file is echoed to the terminal, but \n is stripped, and everything is on a single line. Any ideas what I have to do to have new lines?
Thanks
Upvotes: 2
Views: 922
Reputation: 314
The solution is to use printf '%s\n' "$output"
The key elements are %s
which interprets the output as string, and the double quotes ""
which interpret the entire string as a single input. If you don't add the double quotes then every space is replaced by \n, so you would end up with a single word per line. Obviously, the actual string to display is stored in $output
.
Reference: http://wiki.bash-hackers.org/commands/builtin/printf
Upvotes: 2
Reputation: 1323973
You can try and, in your sh script,
avar
;echo that variable with:
echo -e "${avar}"
That should keep the newlines, as mentioned in "echo multiple lines into a file".
The same link mentions printf
as well.
printf '%s\n' "${avar}"
Upvotes: 2