Meaning of backslash
Clash Royale CLAN TAG#URR8PPP
Why the following command prints Smith
but not Smith
?
echo Smith
bash escape-characters
add a comment |
Why the following command prints Smith
but not Smith
?
echo Smith
bash escape-characters
add a comment |
Why the following command prints Smith
but not Smith
?
echo Smith
bash escape-characters
Why the following command prints Smith
but not Smith
?
echo Smith
bash escape-characters
bash escape-characters
asked Jul 26 '14 at 0:48
DUKEDUKE
2372510
2372510
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
The backslash is an escape character in the shell syntax that:
shall preserve the literal value of the following character, with the exception of a <newline>. ... The <backslash> ... shall be removed
So S
means the same thing as S
, because S
is not a newline character and also not a shell special character that could be escaped ($
, "
, '
, {
, [
, `
, ,
|
, &
, ;
, <
, >
, (
, )
, ?
, *
, [
, #
, ~
, =
, %
, , or tab). To include a literal backslash in the argument given to
echo
, escape it in turn with or any other quoting operator:
echo \Smith
or
echo 'Smith'
or
echo "Smith"
( still retains a special meaning within double quotes, but not when followed by
S
, only when followed by ,
`
, $
, "
or newline).
Now, many echo
implementations also treat specially when found in their argument (though generally not when followed by
S
, though there's no guarantee), so you may want to use printf
instead:
printf '%sn' 'Smith'
note: this is the specified behavior for your example unquoted case, but it can change if it is otherwise quoted or read
in from a file
add a comment |
S
escapes the S
, which is not a special character, thus gives S
. You need to double the backslash to print it: echo \Smith
EDIT: But more generally, it's better to use printf
. See the difference between echo x\by
, which outputs "y" (the "x" gets overwritten by the backspace b
) with some versions of echo
(dash, zsh), and printf "%sn" x\by
, which outputs "xby".
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',
autoActivateHeartbeat: false,
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%2f146663%2fmeaning-of-backslash%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
The backslash is an escape character in the shell syntax that:
shall preserve the literal value of the following character, with the exception of a <newline>. ... The <backslash> ... shall be removed
So S
means the same thing as S
, because S
is not a newline character and also not a shell special character that could be escaped ($
, "
, '
, {
, [
, `
, ,
|
, &
, ;
, <
, >
, (
, )
, ?
, *
, [
, #
, ~
, =
, %
, , or tab). To include a literal backslash in the argument given to
echo
, escape it in turn with or any other quoting operator:
echo \Smith
or
echo 'Smith'
or
echo "Smith"
( still retains a special meaning within double quotes, but not when followed by
S
, only when followed by ,
`
, $
, "
or newline).
Now, many echo
implementations also treat specially when found in their argument (though generally not when followed by
S
, though there's no guarantee), so you may want to use printf
instead:
printf '%sn' 'Smith'
note: this is the specified behavior for your example unquoted case, but it can change if it is otherwise quoted or read
in from a file
add a comment |
The backslash is an escape character in the shell syntax that:
shall preserve the literal value of the following character, with the exception of a <newline>. ... The <backslash> ... shall be removed
So S
means the same thing as S
, because S
is not a newline character and also not a shell special character that could be escaped ($
, "
, '
, {
, [
, `
, ,
|
, &
, ;
, <
, >
, (
, )
, ?
, *
, [
, #
, ~
, =
, %
, , or tab). To include a literal backslash in the argument given to
echo
, escape it in turn with or any other quoting operator:
echo \Smith
or
echo 'Smith'
or
echo "Smith"
( still retains a special meaning within double quotes, but not when followed by
S
, only when followed by ,
`
, $
, "
or newline).
Now, many echo
implementations also treat specially when found in their argument (though generally not when followed by
S
, though there's no guarantee), so you may want to use printf
instead:
printf '%sn' 'Smith'
note: this is the specified behavior for your example unquoted case, but it can change if it is otherwise quoted or read
in from a file
add a comment |
The backslash is an escape character in the shell syntax that:
shall preserve the literal value of the following character, with the exception of a <newline>. ... The <backslash> ... shall be removed
So S
means the same thing as S
, because S
is not a newline character and also not a shell special character that could be escaped ($
, "
, '
, {
, [
, `
, ,
|
, &
, ;
, <
, >
, (
, )
, ?
, *
, [
, #
, ~
, =
, %
, , or tab). To include a literal backslash in the argument given to
echo
, escape it in turn with or any other quoting operator:
echo \Smith
or
echo 'Smith'
or
echo "Smith"
( still retains a special meaning within double quotes, but not when followed by
S
, only when followed by ,
`
, $
, "
or newline).
Now, many echo
implementations also treat specially when found in their argument (though generally not when followed by
S
, though there's no guarantee), so you may want to use printf
instead:
printf '%sn' 'Smith'
note: this is the specified behavior for your example unquoted case, but it can change if it is otherwise quoted or read
in from a file
The backslash is an escape character in the shell syntax that:
shall preserve the literal value of the following character, with the exception of a <newline>. ... The <backslash> ... shall be removed
So S
means the same thing as S
, because S
is not a newline character and also not a shell special character that could be escaped ($
, "
, '
, {
, [
, `
, ,
|
, &
, ;
, <
, >
, (
, )
, ?
, *
, [
, #
, ~
, =
, %
, , or tab). To include a literal backslash in the argument given to
echo
, escape it in turn with or any other quoting operator:
echo \Smith
or
echo 'Smith'
or
echo "Smith"
( still retains a special meaning within double quotes, but not when followed by
S
, only when followed by ,
`
, $
, "
or newline).
Now, many echo
implementations also treat specially when found in their argument (though generally not when followed by
S
, though there's no guarantee), so you may want to use printf
instead:
printf '%sn' 'Smith'
note: this is the specified behavior for your example unquoted case, but it can change if it is otherwise quoted or read
in from a file
edited Feb 1 at 10:17
Stéphane Chazelas
306k57581935
306k57581935
answered Jul 26 '14 at 0:53
Michael HomerMichael Homer
48.7k8130168
48.7k8130168
add a comment |
add a comment |
S
escapes the S
, which is not a special character, thus gives S
. You need to double the backslash to print it: echo \Smith
EDIT: But more generally, it's better to use printf
. See the difference between echo x\by
, which outputs "y" (the "x" gets overwritten by the backspace b
) with some versions of echo
(dash, zsh), and printf "%sn" x\by
, which outputs "xby".
add a comment |
S
escapes the S
, which is not a special character, thus gives S
. You need to double the backslash to print it: echo \Smith
EDIT: But more generally, it's better to use printf
. See the difference between echo x\by
, which outputs "y" (the "x" gets overwritten by the backspace b
) with some versions of echo
(dash, zsh), and printf "%sn" x\by
, which outputs "xby".
add a comment |
S
escapes the S
, which is not a special character, thus gives S
. You need to double the backslash to print it: echo \Smith
EDIT: But more generally, it's better to use printf
. See the difference between echo x\by
, which outputs "y" (the "x" gets overwritten by the backspace b
) with some versions of echo
(dash, zsh), and printf "%sn" x\by
, which outputs "xby".
S
escapes the S
, which is not a special character, thus gives S
. You need to double the backslash to print it: echo \Smith
EDIT: But more generally, it's better to use printf
. See the difference between echo x\by
, which outputs "y" (the "x" gets overwritten by the backspace b
) with some versions of echo
(dash, zsh), and printf "%sn" x\by
, which outputs "xby".
edited Jul 26 '14 at 0:58
answered Jul 26 '14 at 0:53
vinc17vinc17
8,9991736
8,9991736
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.
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%2f146663%2fmeaning-of-backslash%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