Newline In Email Using Paste Command [duplicate]
up vote
0
down vote
favorite
This question already has an answer here:
When to wrap quotes around a shell variable?
5 answers
I am using paste command in the mail that I am sending using shell script.
The output on the console looks perfect but the output in the mail is not in the same format. How do I make the format in the mail too same as in the console. The example below is just an example. The arrays values are dynamic. So I cannot use html table.
#!/bin/bash
BASETABLE[0]="ABC"
BASETABLE[1]="XYZ"
WORKFLOW[0]="123"
WORKFLOW[1]="789"
paste -d' ' <(printf "n") <(printf "n%-12.12sn" "${BASETABLE[@]}") <(printf "n%sn" "${WORKFLOW[@]}")
echo "Test" `paste -d' ' <(printf "n") <(printf "n%-12.12sn" "${BASETABLE[@]}") <(printf "n%sn" "${WORKFLOW[@]}")` | mail -s "Test" user@xyz.com
Outout on Console:
ABC 123
XYZ 789
Output in Mail:
ABC 123 XYZ 789
arrays shell email paste
marked as duplicate by tripleee
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 at 6:58
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
up vote
0
down vote
favorite
This question already has an answer here:
When to wrap quotes around a shell variable?
5 answers
I am using paste command in the mail that I am sending using shell script.
The output on the console looks perfect but the output in the mail is not in the same format. How do I make the format in the mail too same as in the console. The example below is just an example. The arrays values are dynamic. So I cannot use html table.
#!/bin/bash
BASETABLE[0]="ABC"
BASETABLE[1]="XYZ"
WORKFLOW[0]="123"
WORKFLOW[1]="789"
paste -d' ' <(printf "n") <(printf "n%-12.12sn" "${BASETABLE[@]}") <(printf "n%sn" "${WORKFLOW[@]}")
echo "Test" `paste -d' ' <(printf "n") <(printf "n%-12.12sn" "${BASETABLE[@]}") <(printf "n%sn" "${WORKFLOW[@]}")` | mail -s "Test" user@xyz.com
Outout on Console:
ABC 123
XYZ 789
Output in Mail:
ABC 123 XYZ 789
arrays shell email paste
marked as duplicate by tripleee
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 at 6:58
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
This question already has an answer here:
When to wrap quotes around a shell variable?
5 answers
I am using paste command in the mail that I am sending using shell script.
The output on the console looks perfect but the output in the mail is not in the same format. How do I make the format in the mail too same as in the console. The example below is just an example. The arrays values are dynamic. So I cannot use html table.
#!/bin/bash
BASETABLE[0]="ABC"
BASETABLE[1]="XYZ"
WORKFLOW[0]="123"
WORKFLOW[1]="789"
paste -d' ' <(printf "n") <(printf "n%-12.12sn" "${BASETABLE[@]}") <(printf "n%sn" "${WORKFLOW[@]}")
echo "Test" `paste -d' ' <(printf "n") <(printf "n%-12.12sn" "${BASETABLE[@]}") <(printf "n%sn" "${WORKFLOW[@]}")` | mail -s "Test" user@xyz.com
Outout on Console:
ABC 123
XYZ 789
Output in Mail:
ABC 123 XYZ 789
arrays shell email paste
This question already has an answer here:
When to wrap quotes around a shell variable?
5 answers
I am using paste command in the mail that I am sending using shell script.
The output on the console looks perfect but the output in the mail is not in the same format. How do I make the format in the mail too same as in the console. The example below is just an example. The arrays values are dynamic. So I cannot use html table.
#!/bin/bash
BASETABLE[0]="ABC"
BASETABLE[1]="XYZ"
WORKFLOW[0]="123"
WORKFLOW[1]="789"
paste -d' ' <(printf "n") <(printf "n%-12.12sn" "${BASETABLE[@]}") <(printf "n%sn" "${WORKFLOW[@]}")
echo "Test" `paste -d' ' <(printf "n") <(printf "n%-12.12sn" "${BASETABLE[@]}") <(printf "n%sn" "${WORKFLOW[@]}")` | mail -s "Test" user@xyz.com
Outout on Console:
ABC 123
XYZ 789
Output in Mail:
ABC 123 XYZ 789
This question already has an answer here:
When to wrap quotes around a shell variable?
5 answers
arrays shell email paste
arrays shell email paste
asked Nov 22 at 4:20
user3198755
8912
8912
marked as duplicate by tripleee
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 at 6:58
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by tripleee
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 at 6:58
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
The problem is your use of the echo
statement. echo
will not preserve newlines in an unquoted string. For example, if I have a variable containing a newline:
my_variable="This is
a test"
If I echo it without quotes, newlines will be transformed into spaces:
$ echo $my_variable
This is a test
But if I quote the variable, newlines will be preserved:
$ echo "$my_variable"
This is
a test
So you can get the output you want by simply moving the closing quote in your echo
statement, so that it becomes:
echo "Test `paste -d' ' <(printf "n") <(printf "n%-12.12sn" "${BASETABLE[@]}") <(printf "n%sn" "${WORKFLOW[@]}")`"
This will output:
Test
ABC 123
XYZ 789
Instead of:
Test ABC 123 XYZ 789
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
The problem is your use of the echo
statement. echo
will not preserve newlines in an unquoted string. For example, if I have a variable containing a newline:
my_variable="This is
a test"
If I echo it without quotes, newlines will be transformed into spaces:
$ echo $my_variable
This is a test
But if I quote the variable, newlines will be preserved:
$ echo "$my_variable"
This is
a test
So you can get the output you want by simply moving the closing quote in your echo
statement, so that it becomes:
echo "Test `paste -d' ' <(printf "n") <(printf "n%-12.12sn" "${BASETABLE[@]}") <(printf "n%sn" "${WORKFLOW[@]}")`"
This will output:
Test
ABC 123
XYZ 789
Instead of:
Test ABC 123 XYZ 789
add a comment |
up vote
0
down vote
accepted
The problem is your use of the echo
statement. echo
will not preserve newlines in an unquoted string. For example, if I have a variable containing a newline:
my_variable="This is
a test"
If I echo it without quotes, newlines will be transformed into spaces:
$ echo $my_variable
This is a test
But if I quote the variable, newlines will be preserved:
$ echo "$my_variable"
This is
a test
So you can get the output you want by simply moving the closing quote in your echo
statement, so that it becomes:
echo "Test `paste -d' ' <(printf "n") <(printf "n%-12.12sn" "${BASETABLE[@]}") <(printf "n%sn" "${WORKFLOW[@]}")`"
This will output:
Test
ABC 123
XYZ 789
Instead of:
Test ABC 123 XYZ 789
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
The problem is your use of the echo
statement. echo
will not preserve newlines in an unquoted string. For example, if I have a variable containing a newline:
my_variable="This is
a test"
If I echo it without quotes, newlines will be transformed into spaces:
$ echo $my_variable
This is a test
But if I quote the variable, newlines will be preserved:
$ echo "$my_variable"
This is
a test
So you can get the output you want by simply moving the closing quote in your echo
statement, so that it becomes:
echo "Test `paste -d' ' <(printf "n") <(printf "n%-12.12sn" "${BASETABLE[@]}") <(printf "n%sn" "${WORKFLOW[@]}")`"
This will output:
Test
ABC 123
XYZ 789
Instead of:
Test ABC 123 XYZ 789
The problem is your use of the echo
statement. echo
will not preserve newlines in an unquoted string. For example, if I have a variable containing a newline:
my_variable="This is
a test"
If I echo it without quotes, newlines will be transformed into spaces:
$ echo $my_variable
This is a test
But if I quote the variable, newlines will be preserved:
$ echo "$my_variable"
This is
a test
So you can get the output you want by simply moving the closing quote in your echo
statement, so that it becomes:
echo "Test `paste -d' ' <(printf "n") <(printf "n%-12.12sn" "${BASETABLE[@]}") <(printf "n%sn" "${WORKFLOW[@]}")`"
This will output:
Test
ABC 123
XYZ 789
Instead of:
Test ABC 123 XYZ 789
answered Nov 22 at 4:29
larsks
112k18184194
112k18184194
add a comment |
add a comment |