When I execute this command
git log 23237d...1a8815 --oneline --pretty=tformat:"%h %B"
I get something like
1a88151 commit1
8a544c0 commit2
b168aa9 commit3
But when I want to export this to some variable:
export LOG=`git log 23237d...1a8815 --oneline --pretty=tformat:"%h %B"`
And output it: echo $LOG
,
I get this:
1a88151 commit1 8a544c0 commit2 b168aa9 commit3
How can I make multiline export?
You need to quote the expansion of the LOG
variable in the call to echo:
echo "$LOG"
This prevents word splitting from taking place. You don't need to modify the IFS
variable in this case.
Bash processes the input using the contents of the IFS
variable. From the docs:
The Internal Field Separator (IFS) that is used for word splitting after expansion and to split lines into words with the read builtin command. The default value is
<space><tab><newline>
.
You can change the values of IFS
to alter the behaviour:
IFS='' export LOG=`git log 23237d...1a8815 --oneline --pretty=tformat:"%h %B"`
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