Maurice Abdallah
Maurice Abdallah

Reputation: 1

passing text with \n as one argument in shell

i have a file called file1 containing the following

firstname lastname location etc
second line
third line

i am using this code

read a b c < file1
echo $a $b $c

the output i am getting is

firstname lastname location etc

so my program is taking

a = firstname 
b = lastname
c= location etc

how can i get my program to take

c= location etc second line third line

Upvotes: 0

Views: 47

Answers (2)

ahus1
ahus1

Reputation: 5942

Reading your query you want to have everything in one line.

# read file in one variable
c=`cat file1`
# keep everything in a separate line
echo "$c"
# put everything in one line
echo $c

The last echo will produce the output you have in your question:

firstname lastname location etc second line third line

Upvotes: 0

anubhava
anubhava

Reputation: 785376

You can use -d flag in read:

read -d '' a b c < file1

echo "$c"
location etc
second line
third line

Upvotes: 1

Related Questions