how to put quote around variable in shell script
Clash 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
shell-script
add a comment |Â
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
shell-script
Have you triedx="'$line'"
?
â perror
Jul 19 at 15:37
add a comment |Â
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
shell-script
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
shell-script
asked Jul 19 at 15:29
Kppatel Patel
1265
1265
Have you triedx="'$line'"
?
â perror
Jul 19 at 15:37
add a comment |Â
Have you triedx="'$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
add a comment |Â
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'"
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 oftest.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
 |Â
show 3 more comments
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'"
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 oftest.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
 |Â
show 3 more comments
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'"
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 oftest.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
 |Â
show 3 more comments
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'"
The escape characters are not needed for a single quote within double quotes. Double quotes already escape single quotes. Just use:
x="'$line'"
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 oftest.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
 |Â
show 3 more comments
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 oftest.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
 |Â
show 3 more comments
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Have you tried
x="'$line'"
?â perror
Jul 19 at 15:37