BashScripts.org
http://bashscripts.org/forum/

Preserving new line characters with backtics
http://bashscripts.org/forum/viewtopic.php?f=16&t=1756
Page 1 of 1

Author:  gw1500se [ Thu Oct 31, 2013 5:57 pm ]
Post subject:  Preserving new line characters with backtics

I am building an email that combines text and the output from command using backtics. I know about the echo -e option and using quotes but that does not help.
Code:
.
.
.
results=`some command`
message="$message\n$results"
.
.
.
echo -e "$message" | mail yada yada

All the new lines that are added when I create message but the new lines from $result are all gone. How do I preserve that formatting? TIA.

Author:  Watael [ Fri Nov 01, 2013 7:10 am ]
Post subject:  Re: Preserving new line characters with backtics

hi,

I can't reproduce this behaviour.
may be by telling us what `some command` is.

Author:  gw1500se [ Sat Nov 02, 2013 7:04 am ]
Post subject:  Re: Preserving new line characters with backtics

Thanks for the reply. In this case the command is 'dump'.

Author:  Watael [ Sat Nov 02, 2013 7:52 am ]
Post subject:  Re: Preserving new line characters with backtics

Unfortunately I don't have this comand on GNU/Debian.
What does it dumps?
Could you redirect its output to file that you'd upload here as an attachment, so it saves its format?

Author:  gw1500se [ Sat Nov 09, 2013 5:37 am ]
Post subject:  Re: Preserving new line characters with backtics

I hadn't thought of that. I'll give it a try. Thanks.

Author:  gw1500se [ Tue Nov 19, 2013 4:44 am ]
Post subject:  Re: Preserving new line characters with backtics

No joy. The file itself looks correct:
Code:
cat /tmp/dump.txt
  DUMP: Date of this level 18 dump: Tue Nov 19 05:15:12 2013
  DUMP: Date of last level 17 dump: Mon Nov 18 05:07:29 2013
  DUMP: Dumping /dev/sda1 (/boot) to /stage-backup/inc-11192013/boot001
  DUMP: Label: none
  DUMP: Writing 10 Kilobyte records
  DUMP: mapping (Pass I) [regular files]
  DUMP: mapping (Pass II) [directories]
  DUMP: estimated 45 blocks.
  DUMP: Dumping volume 1 on /stage-backup/inc-11192013/boot001
  DUMP: Volume 1 started with block 1 at: Tue Nov 19 05:15:12 2013
  DUMP: dumping (Pass III) [directories]
  DUMP: dumping (Pass IV) [regular files]
  DUMP: Closing /stage-backup/inc-11192013/boot001
  DUMP: Volume 1 completed at: Tue Nov 19 05:15:12 2013
  DUMP: Volume 1 50 blocks (0.05MB)
  DUMP: 50 blocks (0.05MB) on 1 volume(s)
  DUMP: finished in less than a second
  DUMP: Date of this level 18 dump: Tue Nov 19 05:15:12 2013
  DUMP: Date this dump completed:  Tue Nov 19 05:15:12 2013
  DUMP: Average transfer rate: 0 kB/s
  DUMP: DUMP IS DONE

but when I do:
Code:
results=`cat /tmp/dump.txt`
message="$message\n$results"

the resulting email is exactly the same.
Code:
Starting inc dump on 11/19/13 at 02:00:01.
Estimating size of dump for /root
Estimated size of dump for /root is 29151209472
DUMP: Date of this level 18 dump: Tue Nov 19 02:00:08 2013 DUMP: Date of last level 17 dump: Mon Nov 18 02:00:07 2013 DUMP: Dumping /dev/sda3 (/) to /stage-backup/inc-11192013/root001 DUMP: Label: none DUMP: Writing 10 Kilobyte records DUMP: mapping (Pass I) [regular files] DUMP: mapping (Pass II) [directories] DUMP: estimated 28467978 blocks. DUMP: Dumping volume 1 on /stage-backup/inc-11192013/root001 DUMP: Volume 1 started with block 1 at: Tue Nov 19 02:00:13 2013 DUMP: dumping (Pass III) [directories] DUMP: dumping (Pass IV) [regular files] DUMP: 54.71% done at 51919 kB/s, finished in 0:04 DUMP: Closing /stage-backup/inc-11192013/root001 DUMP: Volume 1 completed at: Tue Nov 19 02:09:28 2013 DUMP: Volume 1 28467830 blocks (27800.62MB) DUMP: Volume 1 took 0:09:15 DUMP: Volume 1 transfer rate: 51293 kB/s DUMP: 28467830 blocks (27800.62MB) on 1 volume(s) DUMP: finished in 555 seconds, throughput 51293 kBytes/sec DUMP: Date of this level 18 dump: Tue Nov 19 02:00:08 2013 DUMP: Date this dump completed: Tue Nov 19 02:09:28 2013 DUMP: Average transfer rate: 51293 kB/s DUMP: DUMP IS DONE
inc backup of /root complete at Tue Nov 19 02:09:29 EST 2013

Note that in the file an 'od' shows each line ending in x'0a'. Also, I doubt it matters but this is CentOS 6.

Author:  Watael [ Tue Nov 19, 2013 7:25 am ]
Post subject:  Re: Preserving new line characters with backtics

cat alone won't tell much about format, you need to add the -A option.

Author:  gw1500se [ Wed Nov 20, 2013 8:29 am ]
Post subject:  Re: Preserving new line characters with backtics

Looks good. Shows only '$' at the end of each line.

Page 1 of 1 All times are UTC - 6 hours
© 2000, 2002, 2005, 2007 phpBB Group • http://www.phpbb.com