how to echo $, & symbols correctly?
up vote
0
down vote
favorite
Output &a
on the screen while there is already a defined variable a
. Here is what happened in my bash:
localhost:~ $ a=5
localhost:~ $ echo $$a
83079a
localhost:~ $ echo ^$a
^5
localhost:~ $
I just can't get $a
.
And I found this post: https://stackoverflow.com/questions/4087695/escaping-ampersands-in-windows-batch-files
it says echo a ^& b
will get a & b
, but with my bash I got this:
localhost:~ $ echo a ^& b
[1] 83134
a ^
-bash: b: command not found
shell
add a comment |
up vote
0
down vote
favorite
Output &a
on the screen while there is already a defined variable a
. Here is what happened in my bash:
localhost:~ $ a=5
localhost:~ $ echo $$a
83079a
localhost:~ $ echo ^$a
^5
localhost:~ $
I just can't get $a
.
And I found this post: https://stackoverflow.com/questions/4087695/escaping-ampersands-in-windows-batch-files
it says echo a ^& b
will get a & b
, but with my bash I got this:
localhost:~ $ echo a ^& b
[1] 83134
a ^
-bash: b: command not found
shell
3
did you try to excape using back slash instead of '^' ?
– lese
Sep 4 '15 at 14:03
works. thanks! sorry I never thought of that ...
– AGamePlayer
Sep 4 '15 at 14:04
You can also place things in single quotes'
to get the literal form of anything
– Centimane
Sep 4 '15 at 14:06
You shouldn't be looking at windows batch file information for help with bash. They are different things.
– jw013
Sep 4 '15 at 14:55
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Output &a
on the screen while there is already a defined variable a
. Here is what happened in my bash:
localhost:~ $ a=5
localhost:~ $ echo $$a
83079a
localhost:~ $ echo ^$a
^5
localhost:~ $
I just can't get $a
.
And I found this post: https://stackoverflow.com/questions/4087695/escaping-ampersands-in-windows-batch-files
it says echo a ^& b
will get a & b
, but with my bash I got this:
localhost:~ $ echo a ^& b
[1] 83134
a ^
-bash: b: command not found
shell
Output &a
on the screen while there is already a defined variable a
. Here is what happened in my bash:
localhost:~ $ a=5
localhost:~ $ echo $$a
83079a
localhost:~ $ echo ^$a
^5
localhost:~ $
I just can't get $a
.
And I found this post: https://stackoverflow.com/questions/4087695/escaping-ampersands-in-windows-batch-files
it says echo a ^& b
will get a & b
, but with my bash I got this:
localhost:~ $ echo a ^& b
[1] 83134
a ^
-bash: b: command not found
shell
shell
edited yesterday
Rui F Ribeiro
38.6k1479128
38.6k1479128
asked Sep 4 '15 at 13:56
AGamePlayer
1,976102942
1,976102942
3
did you try to excape using back slash instead of '^' ?
– lese
Sep 4 '15 at 14:03
works. thanks! sorry I never thought of that ...
– AGamePlayer
Sep 4 '15 at 14:04
You can also place things in single quotes'
to get the literal form of anything
– Centimane
Sep 4 '15 at 14:06
You shouldn't be looking at windows batch file information for help with bash. They are different things.
– jw013
Sep 4 '15 at 14:55
add a comment |
3
did you try to excape using back slash instead of '^' ?
– lese
Sep 4 '15 at 14:03
works. thanks! sorry I never thought of that ...
– AGamePlayer
Sep 4 '15 at 14:04
You can also place things in single quotes'
to get the literal form of anything
– Centimane
Sep 4 '15 at 14:06
You shouldn't be looking at windows batch file information for help with bash. They are different things.
– jw013
Sep 4 '15 at 14:55
3
3
did you try to excape using back slash instead of '^' ?
– lese
Sep 4 '15 at 14:03
did you try to excape using back slash instead of '^' ?
– lese
Sep 4 '15 at 14:03
works. thanks! sorry I never thought of that ...
– AGamePlayer
Sep 4 '15 at 14:04
works. thanks! sorry I never thought of that ...
– AGamePlayer
Sep 4 '15 at 14:04
You can also place things in single quotes
'
to get the literal form of anything– Centimane
Sep 4 '15 at 14:06
You can also place things in single quotes
'
to get the literal form of anything– Centimane
Sep 4 '15 at 14:06
You shouldn't be looking at windows batch file information for help with bash. They are different things.
– jw013
Sep 4 '15 at 14:55
You shouldn't be looking at windows batch file information for help with bash. They are different things.
– jw013
Sep 4 '15 at 14:55
add a comment |
2 Answers
2
active
oldest
votes
up vote
4
down vote
accepted
Use double quotes to echo
a variable
localhost:~ $ a=5
localhost:~ $ echo "$a"
5
localhost:~ $ echo '$a'
$a
localhost:~ $ echo "a & b"
a & b
Or backslash to escape and not use quotes
localhost:~ $ echo a & b
a & b
localhost:~ $ echo $a
$a
add a comment |
up vote
0
down vote
r@S:/tmp # a=10
r@S:/tmp # echo $a
10
r@S:/tmp # echo $a
$a
r@S:/tmp #
add a comment |
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: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f227516%2fhow-to-echo-symbols-correctly%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
Use double quotes to echo
a variable
localhost:~ $ a=5
localhost:~ $ echo "$a"
5
localhost:~ $ echo '$a'
$a
localhost:~ $ echo "a & b"
a & b
Or backslash to escape and not use quotes
localhost:~ $ echo a & b
a & b
localhost:~ $ echo $a
$a
add a comment |
up vote
4
down vote
accepted
Use double quotes to echo
a variable
localhost:~ $ a=5
localhost:~ $ echo "$a"
5
localhost:~ $ echo '$a'
$a
localhost:~ $ echo "a & b"
a & b
Or backslash to escape and not use quotes
localhost:~ $ echo a & b
a & b
localhost:~ $ echo $a
$a
add a comment |
up vote
4
down vote
accepted
up vote
4
down vote
accepted
Use double quotes to echo
a variable
localhost:~ $ a=5
localhost:~ $ echo "$a"
5
localhost:~ $ echo '$a'
$a
localhost:~ $ echo "a & b"
a & b
Or backslash to escape and not use quotes
localhost:~ $ echo a & b
a & b
localhost:~ $ echo $a
$a
Use double quotes to echo
a variable
localhost:~ $ a=5
localhost:~ $ echo "$a"
5
localhost:~ $ echo '$a'
$a
localhost:~ $ echo "a & b"
a & b
Or backslash to escape and not use quotes
localhost:~ $ echo a & b
a & b
localhost:~ $ echo $a
$a
edited Sep 4 '15 at 14:25
answered Sep 4 '15 at 14:17
tachomi
3,56731134
3,56731134
add a comment |
add a comment |
up vote
0
down vote
r@S:/tmp # a=10
r@S:/tmp # echo $a
10
r@S:/tmp # echo $a
$a
r@S:/tmp #
add a comment |
up vote
0
down vote
r@S:/tmp # a=10
r@S:/tmp # echo $a
10
r@S:/tmp # echo $a
$a
r@S:/tmp #
add a comment |
up vote
0
down vote
up vote
0
down vote
r@S:/tmp # a=10
r@S:/tmp # echo $a
10
r@S:/tmp # echo $a
$a
r@S:/tmp #
r@S:/tmp # a=10
r@S:/tmp # echo $a
10
r@S:/tmp # echo $a
$a
r@S:/tmp #
answered Sep 4 '15 at 14:20
SHW
7,98633570
7,98633570
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f227516%2fhow-to-echo-symbols-correctly%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
did you try to excape using back slash instead of '^' ?
– lese
Sep 4 '15 at 14:03
works. thanks! sorry I never thought of that ...
– AGamePlayer
Sep 4 '15 at 14:04
You can also place things in single quotes
'
to get the literal form of anything– Centimane
Sep 4 '15 at 14:06
You shouldn't be looking at windows batch file information for help with bash. They are different things.
– jw013
Sep 4 '15 at 14:55