Carriage return with cat variable

Hi,

I wish to know how to works the carriage return with cat.. As a picture often speaks better than words, my code below :

#te=`cat text.txt` (I tried this, but the same..)
te=$(cat text.txt)

echo $te

My file text.txt below:

BLABLABLABLABLALBLA

BLABLABLABLABLALBLA

BLABLABLABLABLALBLA

The Output :

BLABLABLABLABLALBLA BLABLABLABLABLALBLA BLABLABLABLABLALBLA

I tried "\n" into text.txt, the same.. Please who can help me ?

Thanks by advance. :b:

where are you trying? on a PC after having copied the file in Widows?
because if your txt file has 3 line cat will display 3 lines... ( in other words it looks like a DOS conversion with Line feed you are after...
Here on a debian:

"blabla.txt" [New File] 4 lines, 40 characters written
xns:/home/vbe $ cat blabla.txt
blablalba
blablalba
blablalba
blablalba

On linux

---------- Post updated at 12:06 PM ---------- Previous update was at 12:01 PM ----------

Yes me too, but I do :

echo $te

The output doesn't the carriage return :frowning:

Don't mix up "carriage return" with "\n" (which is "line feed"). When expanding an unquoted variable (with the default IFS variable), ALL whitespace will be replaced by the first IFS character, usually a space. That's why the "\n" is "lost"...

1 Like

I want to put (cat file.txt) because after I use the variable for send an email with sendemail example :

/usr/bin/sendemail -f $sender -t $recipient -u $subject -m $te -s $server

Did you try?:

 echo "$te"
1 Like

mhhh... I understand, there is another solution?

xns1:/home/vbe $ cat blabla.txt
blablalba
blablalba
blablalba
blablalba
xns1:/home/vbe $ te=$(cat blabla.txt)
xns1:/home/vbe $ echo $te
blablalba blablalba blablalba blablalba
xns1:/home/vbe $ echo "$te"
blablalba
blablalba
blablalba
blablalba
xns1:/home/vbe $
1 Like

I suggest echo "$te" as suggested above. The quotes are important.

1 Like

So, I try to be more clear :

Example (in my file.txt) :

BLABLA
blablabla
etc...
(I need of line feed)
BLABLA
blablabla
(I need of line feed)
blablabla\
etc...

My script into another file :

#!/bin/bash

sender="me@example.com"
recipient="you@example.com"
subject="TEST FILE"
server="0.0.0.0"

file=$(I want to read my file with cat or another...with the line feed)

/usr/bin/sendemail -f $sender -t $recipient -u $subject -m $file

:o:wall:

---------- Post updated at 12:37 PM ---------- Previous update was at 12:36 PM ----------

Thank you very much ! That works :):slight_smile: And sorry I didn't understand the quotes...I'm ashamed :o

1 Like