Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 01-10-2013, 11:24 PM   #1
Registered: Jan 2012
Location: Mumbai
Posts: 63

Rep: Reputation: Disabled
Difference between echo of file within double quotes and without double quotes

Hello All,

I had a file which i have copied in variable FIL, but when i do echo to FIL variable (without double quotes) it shows the content of file in un-ordered manner and even the other file name present in directory comes as part of content FIL variable whereas when i echo the FIL variable with double quotes it shows the exact content of file in FIL variable.

test is the name of file with say 50 lines

FIL is the variable in which i am storing it temporary.

FIL=`cat test`

echo $FIL
Above echo of FIL is showing absurd result.

FIL=`cat test`

echo "$FIL"
Whereas this code is showing correct result. Please explain the difference. How come all the new lines present in temp file are getting eaten and files present in directory also gets include in FIL when echoed without double quotes.

Old 01-11-2013, 12:41 AM   #2
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 18,828

Rep: Reputation: 6386Reputation: 6386Reputation: 6386Reputation: 6386Reputation: 6386Reputation: 6386Reputation: 6386Reputation: 6386Reputation: 6386Reputation: 6386Reputation: 6386
you need to check how ' " and ` work in bash. Actually in the first case (echo $FIL) the content of $FIL will be evaluated by the shell during execution. Just try:
echo $FIL
echo '$FIL'
echo "$FIL"
see here:,,, but others may know better links...
Old 01-11-2013, 09:02 AM   #3
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
It is a fairly unusual programming pattern to store all of the content of a multi-line text file in a single scalar variable. More often, a variable is used to hold a single line read from a file, or perhaps an array variable holding one line per element. If the file must be processed in some way, it is conventional to read it, usually line-by-line, into a variable in some programming loop structure. If you can explain some of the bigger picture for your intention, perhaps a better solution to you problem can be suggested.

--- rod.
1 members found this post helpful.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
translate value from single quotes to double quotes venkateshrupineni Linux - Newbie 2 06-14-2012 03:03 PM
Double Quotes Inside Double Quotes youarefunny Programming 6 06-09-2010 10:21 PM
Problems with quotes and double quotes Andruha Slackware 6 01-02-2010 04:44 PM
Using single quotes vs double quotes in PHP strings vharishankar Programming 6 07-11-2005 11:41 AM
In BASH shell, what is the difference in usage between single and double quotes? davidas Linux - Newbie 2 04-05-2004 03:00 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:40 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration