how to put quote around variable in shell script

Multi tool use
Multi tool use

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
1
down vote

favorite












My code is as below,



file="test.text"
while IFS= read line
do
# display $line or do somthing with $line
x="'$line'"
echo $x
# sleep 10

done <"$file"


However, this one gives me following result.



'google.com


Any help is appreciated







share|improve this question



















  • Have you tried x="'$line'" ?
    – perror
    Jul 19 at 15:37
















up vote
1
down vote

favorite












My code is as below,



file="test.text"
while IFS= read line
do
# display $line or do somthing with $line
x="'$line'"
echo $x
# sleep 10

done <"$file"


However, this one gives me following result.



'google.com


Any help is appreciated







share|improve this question



















  • Have you tried x="'$line'" ?
    – perror
    Jul 19 at 15:37












up vote
1
down vote

favorite









up vote
1
down vote

favorite











My code is as below,



file="test.text"
while IFS= read line
do
# display $line or do somthing with $line
x="'$line'"
echo $x
# sleep 10

done <"$file"


However, this one gives me following result.



'google.com


Any help is appreciated







share|improve this question











My code is as below,



file="test.text"
while IFS= read line
do
# display $line or do somthing with $line
x="'$line'"
echo $x
# sleep 10

done <"$file"


However, this one gives me following result.



'google.com


Any help is appreciated









share|improve this question










share|improve this question




share|improve this question









asked Jul 19 at 15:29









Kppatel Patel

1265




1265











  • Have you tried x="'$line'" ?
    – perror
    Jul 19 at 15:37
















  • Have you tried x="'$line'" ?
    – perror
    Jul 19 at 15:37















Have you tried x="'$line'" ?
– perror
Jul 19 at 15:37




Have you tried x="'$line'" ?
– perror
Jul 19 at 15:37










1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










The escape characters are not needed for a single quote within double quotes. Double quotes already escape single quotes. Just use:



x="'$line'"





share|improve this answer























  • It gives me following out put 'google.com, it doesn't add quote around end
    – Kppatel Patel
    Jul 19 at 15:37











  • @KppatelPatel: what are the contents of test.text?
    – Jesse_b
    Jul 19 at 15:38










  • file that is converted from CSV to text, each line is just url
    – Kppatel Patel
    Jul 19 at 15:40










  • @KppatelPatel: I think you have a typo somewhere in your code that isn't displayed here than because it works fine for me.
    – Jesse_b
    Jul 19 at 15:44










  • It seems like something is wrong when I convert csv to text file, when I diligently copy data from file to another file, it worked.
    – Kppatel Patel
    Jul 19 at 15:47










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f457246%2fhow-to-put-quote-around-variable-in-shell-script%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










The escape characters are not needed for a single quote within double quotes. Double quotes already escape single quotes. Just use:



x="'$line'"





share|improve this answer























  • It gives me following out put 'google.com, it doesn't add quote around end
    – Kppatel Patel
    Jul 19 at 15:37











  • @KppatelPatel: what are the contents of test.text?
    – Jesse_b
    Jul 19 at 15:38










  • file that is converted from CSV to text, each line is just url
    – Kppatel Patel
    Jul 19 at 15:40










  • @KppatelPatel: I think you have a typo somewhere in your code that isn't displayed here than because it works fine for me.
    – Jesse_b
    Jul 19 at 15:44










  • It seems like something is wrong when I convert csv to text file, when I diligently copy data from file to another file, it worked.
    – Kppatel Patel
    Jul 19 at 15:47














up vote
2
down vote



accepted










The escape characters are not needed for a single quote within double quotes. Double quotes already escape single quotes. Just use:



x="'$line'"





share|improve this answer























  • It gives me following out put 'google.com, it doesn't add quote around end
    – Kppatel Patel
    Jul 19 at 15:37











  • @KppatelPatel: what are the contents of test.text?
    – Jesse_b
    Jul 19 at 15:38










  • file that is converted from CSV to text, each line is just url
    – Kppatel Patel
    Jul 19 at 15:40










  • @KppatelPatel: I think you have a typo somewhere in your code that isn't displayed here than because it works fine for me.
    – Jesse_b
    Jul 19 at 15:44










  • It seems like something is wrong when I convert csv to text file, when I diligently copy data from file to another file, it worked.
    – Kppatel Patel
    Jul 19 at 15:47












up vote
2
down vote



accepted







up vote
2
down vote



accepted






The escape characters are not needed for a single quote within double quotes. Double quotes already escape single quotes. Just use:



x="'$line'"





share|improve this answer















The escape characters are not needed for a single quote within double quotes. Double quotes already escape single quotes. Just use:



x="'$line'"






share|improve this answer















share|improve this answer



share|improve this answer








edited Jul 19 at 15:41


























answered Jul 19 at 15:36









Jesse_b

10.1k22658




10.1k22658











  • It gives me following out put 'google.com, it doesn't add quote around end
    – Kppatel Patel
    Jul 19 at 15:37











  • @KppatelPatel: what are the contents of test.text?
    – Jesse_b
    Jul 19 at 15:38










  • file that is converted from CSV to text, each line is just url
    – Kppatel Patel
    Jul 19 at 15:40










  • @KppatelPatel: I think you have a typo somewhere in your code that isn't displayed here than because it works fine for me.
    – Jesse_b
    Jul 19 at 15:44










  • It seems like something is wrong when I convert csv to text file, when I diligently copy data from file to another file, it worked.
    – Kppatel Patel
    Jul 19 at 15:47
















  • It gives me following out put 'google.com, it doesn't add quote around end
    – Kppatel Patel
    Jul 19 at 15:37











  • @KppatelPatel: what are the contents of test.text?
    – Jesse_b
    Jul 19 at 15:38










  • file that is converted from CSV to text, each line is just url
    – Kppatel Patel
    Jul 19 at 15:40










  • @KppatelPatel: I think you have a typo somewhere in your code that isn't displayed here than because it works fine for me.
    – Jesse_b
    Jul 19 at 15:44










  • It seems like something is wrong when I convert csv to text file, when I diligently copy data from file to another file, it worked.
    – Kppatel Patel
    Jul 19 at 15:47















It gives me following out put 'google.com, it doesn't add quote around end
– Kppatel Patel
Jul 19 at 15:37





It gives me following out put 'google.com, it doesn't add quote around end
– Kppatel Patel
Jul 19 at 15:37













@KppatelPatel: what are the contents of test.text?
– Jesse_b
Jul 19 at 15:38




@KppatelPatel: what are the contents of test.text?
– Jesse_b
Jul 19 at 15:38












file that is converted from CSV to text, each line is just url
– Kppatel Patel
Jul 19 at 15:40




file that is converted from CSV to text, each line is just url
– Kppatel Patel
Jul 19 at 15:40












@KppatelPatel: I think you have a typo somewhere in your code that isn't displayed here than because it works fine for me.
– Jesse_b
Jul 19 at 15:44




@KppatelPatel: I think you have a typo somewhere in your code that isn't displayed here than because it works fine for me.
– Jesse_b
Jul 19 at 15:44












It seems like something is wrong when I convert csv to text file, when I diligently copy data from file to another file, it worked.
– Kppatel Patel
Jul 19 at 15:47




It seems like something is wrong when I convert csv to text file, when I diligently copy data from file to another file, it worked.
– Kppatel Patel
Jul 19 at 15:47












 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f457246%2fhow-to-put-quote-around-variable-in-shell-script%23new-answer', 'question_page');

);

Post as a guest













































































lL0ZmqG
e di,Q,Jc,OQOVM i jzn5cc l8L5SL YFxjQL,3SPICtwkk0qMMLY7oBQSqk2oLMeVq5wU0o

Popular posts from this blog

How to check contact read email or not when send email to Individual?

How many registers does an x86_64 CPU actually have?

Displaying single band from multi-band raster using QGIS