How do I suppress stderr warning messages from a command inside command substitution?How can I store output in bash variable and suppress output to stderr and stdout?Command substitution and spacessuppress stderr messages in a bash scriptCommand substitutionIs a script running inside command substitution?Using a command inside a sed substitutioncommand substitution inside awkblocking/non-blocking pipes/redirects inside command substitutionGetting no output from command substitution?How to make bash substitution $(<“filename”) silentHow to suppress stdout / stderr from a shell script output?
When blogging recipes, how can I support both readers who want the narrative/journey and ones who want the printer-friendly recipe?
Are there any consumables that function as addictive (psychedelic) drugs?
Why was the small council so happy for Tyrion to become the Master of Coin?
LED on same Pin as Toggle Switch, not illuminating
What defenses are there against being summoned by the Gate spell?
Why don't electron-positron collisions release infinite energy?
Do airline pilots ever risk not hearing communication directed to them specifically, from traffic controllers?
Is there a familial term for apples and pears?
Download, install and reboot computer at night if needed
How is the claim "I am in New York only if I am in America" the same as "If I am in New York, then I am in America?
Why is "Reports" in sentence down without "The"
What do you call something that goes against the spirit of the law, but is legal when interpreting the law to the letter?
Why did the Germans forbid the possession of pet pigeons in Rostov-on-Don in 1941?
How does one intimidate enemies without having the capacity for violence?
New order #4: World
Why is this code 6.5x slower with optimizations enabled?
Shell script can be run only with sh command
What is the meaning of "of trouble" in the following sentence?
What is the white spray-pattern residue inside these Falcon Heavy nozzles?
whey we use polarized capacitor?
Extreme, but not acceptable situation and I can't start the work tomorrow morning
How to make payment on the internet without leaving a money trail?
Is there really no realistic way for a skeleton monster to move around without magic?
What are these boxed doors outside store fronts in New York?
How do I suppress stderr warning messages from a command inside command substitution?
How can I store output in bash variable and suppress output to stderr and stdout?Command substitution and spacessuppress stderr messages in a bash scriptCommand substitutionIs a script running inside command substitution?Using a command inside a sed substitutioncommand substitution inside awkblocking/non-blocking pipes/redirects inside command substitutionGetting no output from command substitution?How to make bash substitution $(<“filename”) silentHow to suppress stdout / stderr from a shell script output?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
touch ~/deleted/$(echo "directory_"$(readlink -f foo)|tr '/' '') 2> /dev/null
where foo is a directory
It's reading the full pathname of foo and creating it as a file replacing all '/' with '' and putting a directory_ in front so the directory /home/test/foo
would create a file directory_hometestfoo
It does exactly what I want except a warning keeps printing tr: warning: an unescaped backslash at end of string is not portable
a. I don't know what that means
b. I would like it to not show
I tried to redirect stderr to /dev/null
but it doesn't work. How do I suppress it?
bash command-substitution stderr
add a comment |
touch ~/deleted/$(echo "directory_"$(readlink -f foo)|tr '/' '') 2> /dev/null
where foo is a directory
It's reading the full pathname of foo and creating it as a file replacing all '/' with '' and putting a directory_ in front so the directory /home/test/foo
would create a file directory_hometestfoo
It does exactly what I want except a warning keeps printing tr: warning: an unescaped backslash at end of string is not portable
a. I don't know what that means
b. I would like it to not show
I tried to redirect stderr to /dev/null
but it doesn't work. How do I suppress it?
bash command-substitution stderr
Please edit and clarify how you use this. Are you calling it as a function? Where is$1
defined? You should also be aware that while
– terdon♦
Aug 6 '14 at 14:37
It's in a script. to run it I "sh script nameOfDirectory"
– lonewarrior556
Aug 6 '14 at 14:38
3
Please edit your question to clarify accordingly. I also strongly suggest you consider using any other character but
– terdon♦
Aug 6 '14 at 14:39
add a comment |
touch ~/deleted/$(echo "directory_"$(readlink -f foo)|tr '/' '') 2> /dev/null
where foo is a directory
It's reading the full pathname of foo and creating it as a file replacing all '/' with '' and putting a directory_ in front so the directory /home/test/foo
would create a file directory_hometestfoo
It does exactly what I want except a warning keeps printing tr: warning: an unescaped backslash at end of string is not portable
a. I don't know what that means
b. I would like it to not show
I tried to redirect stderr to /dev/null
but it doesn't work. How do I suppress it?
bash command-substitution stderr
touch ~/deleted/$(echo "directory_"$(readlink -f foo)|tr '/' '') 2> /dev/null
where foo is a directory
It's reading the full pathname of foo and creating it as a file replacing all '/' with '' and putting a directory_ in front so the directory /home/test/foo
would create a file directory_hometestfoo
It does exactly what I want except a warning keeps printing tr: warning: an unescaped backslash at end of string is not portable
a. I don't know what that means
b. I would like it to not show
I tried to redirect stderr to /dev/null
but it doesn't work. How do I suppress it?
bash command-substitution stderr
bash command-substitution stderr
edited Apr 5 at 3:00
muru
37.2k589164
37.2k589164
asked Aug 6 '14 at 14:32
lonewarrior556lonewarrior556
6683813
6683813
Please edit and clarify how you use this. Are you calling it as a function? Where is$1
defined? You should also be aware that while
– terdon♦
Aug 6 '14 at 14:37
It's in a script. to run it I "sh script nameOfDirectory"
– lonewarrior556
Aug 6 '14 at 14:38
3
Please edit your question to clarify accordingly. I also strongly suggest you consider using any other character but
– terdon♦
Aug 6 '14 at 14:39
add a comment |
Please edit and clarify how you use this. Are you calling it as a function? Where is$1
defined? You should also be aware that while
– terdon♦
Aug 6 '14 at 14:37
It's in a script. to run it I "sh script nameOfDirectory"
– lonewarrior556
Aug 6 '14 at 14:38
3
Please edit your question to clarify accordingly. I also strongly suggest you consider using any other character but
– terdon♦
Aug 6 '14 at 14:39
Please edit and clarify how you use this. Are you calling it as a function? Where is
$1
defined? You should also be aware that while
are allowed in file names, it is a Very Bad Idea® to include them and it will lead to all sorts of trouble later on.– terdon♦
Aug 6 '14 at 14:37
Please edit and clarify how you use this. Are you calling it as a function? Where is
$1
defined? You should also be aware that while
are allowed in file names, it is a Very Bad Idea® to include them and it will lead to all sorts of trouble later on.– terdon♦
Aug 6 '14 at 14:37
It's in a script. to run it I "sh script nameOfDirectory"
– lonewarrior556
Aug 6 '14 at 14:38
It's in a script. to run it I "sh script nameOfDirectory"
– lonewarrior556
Aug 6 '14 at 14:38
3
3
Please edit your question to clarify accordingly. I also strongly suggest you consider using any other character but
, backslashes are special as you're finding out.– terdon♦
Aug 6 '14 at 14:39
Please edit your question to clarify accordingly. I also strongly suggest you consider using any other character but
, backslashes are special as you're finding out.– terdon♦
Aug 6 '14 at 14:39
add a comment |
3 Answers
3
active
oldest
votes
Some expansions happen before redirection so you have to place it directly against your tr
command:
touch ~/deleted/$(echo "directory_"$(readlink -f foo)|tr '/' '' 2> /dev/null)
add a comment |
The error message means that you have an unescaped backslash. In the *nix world, special characters are 'escaped' by adding a backslash before them. That means that they're interpreted as simple characters and not special ones. For example:
$ printf 'foonbar'
foo
bar
The n
is a special character that means newline. But if we escape the slash we get:
$ printf 'foo\nbar'
foonbar
So, you can get rid of it either by escaping the backslash:
touch ~/deleted/"$(echo "directory_$(readlink -f -- "$1")"|tr '/' '\')
Or by redirecting the error output of tr
(not of touch
which is what you were doing):
touch ~/deleted/"$(echo "directory_$(readlink -f -- "$1")"|tr '/' '' 2> /dev/null)
However, I cannot stress enough that it is a Very Bad Idea® to create file names with backslashes. Really. They will be hell to parse and deal with later on. Why not use another character?
Maybe the OP from windows environment?
– cuonglm
Aug 6 '14 at 15:16
@Gnouc yes, which means it's an even worse idea to use ``.
– terdon♦
Aug 6 '14 at 15:18
Git Bash in Windows 10 complains about[...] | tr '\' '/'
although the backslash is properly escaped. Go figure.
– Rolf
Jan 23 at 16:58
@Rolf Windows uses `` as the path delimiter, so that might cause issues there.
– terdon♦
Jan 23 at 17:19
add a comment |
Use single quotes with double back slash, and you will not get any error.
touch ~/deleted/$(echo "directory_"$(readlink -f foo)|tr '/' '\')
Fun thing is, ifurl=D:ProgramsGitmingw64/share/doc/git-doc/git-log.html
then ``url1=echo $url | tr '\ '/'``` shows the warning, while
url1=$(echo $url | tr '\' '/')` does not.
– ThomasH
Dec 19 '18 at 9:00
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%2f148761%2fhow-do-i-suppress-stderr-warning-messages-from-a-command-inside-command-substitu%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Some expansions happen before redirection so you have to place it directly against your tr
command:
touch ~/deleted/$(echo "directory_"$(readlink -f foo)|tr '/' '' 2> /dev/null)
add a comment |
Some expansions happen before redirection so you have to place it directly against your tr
command:
touch ~/deleted/$(echo "directory_"$(readlink -f foo)|tr '/' '' 2> /dev/null)
add a comment |
Some expansions happen before redirection so you have to place it directly against your tr
command:
touch ~/deleted/$(echo "directory_"$(readlink -f foo)|tr '/' '' 2> /dev/null)
Some expansions happen before redirection so you have to place it directly against your tr
command:
touch ~/deleted/$(echo "directory_"$(readlink -f foo)|tr '/' '' 2> /dev/null)
answered Aug 6 '14 at 14:43
konsoleboxkonsolebox
1,297109
1,297109
add a comment |
add a comment |
The error message means that you have an unescaped backslash. In the *nix world, special characters are 'escaped' by adding a backslash before them. That means that they're interpreted as simple characters and not special ones. For example:
$ printf 'foonbar'
foo
bar
The n
is a special character that means newline. But if we escape the slash we get:
$ printf 'foo\nbar'
foonbar
So, you can get rid of it either by escaping the backslash:
touch ~/deleted/"$(echo "directory_$(readlink -f -- "$1")"|tr '/' '\')
Or by redirecting the error output of tr
(not of touch
which is what you were doing):
touch ~/deleted/"$(echo "directory_$(readlink -f -- "$1")"|tr '/' '' 2> /dev/null)
However, I cannot stress enough that it is a Very Bad Idea® to create file names with backslashes. Really. They will be hell to parse and deal with later on. Why not use another character?
Maybe the OP from windows environment?
– cuonglm
Aug 6 '14 at 15:16
@Gnouc yes, which means it's an even worse idea to use ``.
– terdon♦
Aug 6 '14 at 15:18
Git Bash in Windows 10 complains about[...] | tr '\' '/'
although the backslash is properly escaped. Go figure.
– Rolf
Jan 23 at 16:58
@Rolf Windows uses `` as the path delimiter, so that might cause issues there.
– terdon♦
Jan 23 at 17:19
add a comment |
The error message means that you have an unescaped backslash. In the *nix world, special characters are 'escaped' by adding a backslash before them. That means that they're interpreted as simple characters and not special ones. For example:
$ printf 'foonbar'
foo
bar
The n
is a special character that means newline. But if we escape the slash we get:
$ printf 'foo\nbar'
foonbar
So, you can get rid of it either by escaping the backslash:
touch ~/deleted/"$(echo "directory_$(readlink -f -- "$1")"|tr '/' '\')
Or by redirecting the error output of tr
(not of touch
which is what you were doing):
touch ~/deleted/"$(echo "directory_$(readlink -f -- "$1")"|tr '/' '' 2> /dev/null)
However, I cannot stress enough that it is a Very Bad Idea® to create file names with backslashes. Really. They will be hell to parse and deal with later on. Why not use another character?
Maybe the OP from windows environment?
– cuonglm
Aug 6 '14 at 15:16
@Gnouc yes, which means it's an even worse idea to use ``.
– terdon♦
Aug 6 '14 at 15:18
Git Bash in Windows 10 complains about[...] | tr '\' '/'
although the backslash is properly escaped. Go figure.
– Rolf
Jan 23 at 16:58
@Rolf Windows uses `` as the path delimiter, so that might cause issues there.
– terdon♦
Jan 23 at 17:19
add a comment |
The error message means that you have an unescaped backslash. In the *nix world, special characters are 'escaped' by adding a backslash before them. That means that they're interpreted as simple characters and not special ones. For example:
$ printf 'foonbar'
foo
bar
The n
is a special character that means newline. But if we escape the slash we get:
$ printf 'foo\nbar'
foonbar
So, you can get rid of it either by escaping the backslash:
touch ~/deleted/"$(echo "directory_$(readlink -f -- "$1")"|tr '/' '\')
Or by redirecting the error output of tr
(not of touch
which is what you were doing):
touch ~/deleted/"$(echo "directory_$(readlink -f -- "$1")"|tr '/' '' 2> /dev/null)
However, I cannot stress enough that it is a Very Bad Idea® to create file names with backslashes. Really. They will be hell to parse and deal with later on. Why not use another character?
The error message means that you have an unescaped backslash. In the *nix world, special characters are 'escaped' by adding a backslash before them. That means that they're interpreted as simple characters and not special ones. For example:
$ printf 'foonbar'
foo
bar
The n
is a special character that means newline. But if we escape the slash we get:
$ printf 'foo\nbar'
foonbar
So, you can get rid of it either by escaping the backslash:
touch ~/deleted/"$(echo "directory_$(readlink -f -- "$1")"|tr '/' '\')
Or by redirecting the error output of tr
(not of touch
which is what you were doing):
touch ~/deleted/"$(echo "directory_$(readlink -f -- "$1")"|tr '/' '' 2> /dev/null)
However, I cannot stress enough that it is a Very Bad Idea® to create file names with backslashes. Really. They will be hell to parse and deal with later on. Why not use another character?
edited Aug 6 '14 at 15:21
Stéphane Chazelas
313k57593949
313k57593949
answered Aug 6 '14 at 14:43
terdon♦terdon
134k33268449
134k33268449
Maybe the OP from windows environment?
– cuonglm
Aug 6 '14 at 15:16
@Gnouc yes, which means it's an even worse idea to use ``.
– terdon♦
Aug 6 '14 at 15:18
Git Bash in Windows 10 complains about[...] | tr '\' '/'
although the backslash is properly escaped. Go figure.
– Rolf
Jan 23 at 16:58
@Rolf Windows uses `` as the path delimiter, so that might cause issues there.
– terdon♦
Jan 23 at 17:19
add a comment |
Maybe the OP from windows environment?
– cuonglm
Aug 6 '14 at 15:16
@Gnouc yes, which means it's an even worse idea to use ``.
– terdon♦
Aug 6 '14 at 15:18
Git Bash in Windows 10 complains about[...] | tr '\' '/'
although the backslash is properly escaped. Go figure.
– Rolf
Jan 23 at 16:58
@Rolf Windows uses `` as the path delimiter, so that might cause issues there.
– terdon♦
Jan 23 at 17:19
Maybe the OP from windows environment?
– cuonglm
Aug 6 '14 at 15:16
Maybe the OP from windows environment?
– cuonglm
Aug 6 '14 at 15:16
@Gnouc yes, which means it's an even worse idea to use ``.
– terdon♦
Aug 6 '14 at 15:18
@Gnouc yes, which means it's an even worse idea to use ``.
– terdon♦
Aug 6 '14 at 15:18
Git Bash in Windows 10 complains about
[...] | tr '\' '/'
although the backslash is properly escaped. Go figure.– Rolf
Jan 23 at 16:58
Git Bash in Windows 10 complains about
[...] | tr '\' '/'
although the backslash is properly escaped. Go figure.– Rolf
Jan 23 at 16:58
@Rolf Windows uses `` as the path delimiter, so that might cause issues there.
– terdon♦
Jan 23 at 17:19
@Rolf Windows uses `` as the path delimiter, so that might cause issues there.
– terdon♦
Jan 23 at 17:19
add a comment |
Use single quotes with double back slash, and you will not get any error.
touch ~/deleted/$(echo "directory_"$(readlink -f foo)|tr '/' '\')
Fun thing is, ifurl=D:ProgramsGitmingw64/share/doc/git-doc/git-log.html
then ``url1=echo $url | tr '\ '/'``` shows the warning, while
url1=$(echo $url | tr '\' '/')` does not.
– ThomasH
Dec 19 '18 at 9:00
add a comment |
Use single quotes with double back slash, and you will not get any error.
touch ~/deleted/$(echo "directory_"$(readlink -f foo)|tr '/' '\')
Fun thing is, ifurl=D:ProgramsGitmingw64/share/doc/git-doc/git-log.html
then ``url1=echo $url | tr '\ '/'``` shows the warning, while
url1=$(echo $url | tr '\' '/')` does not.
– ThomasH
Dec 19 '18 at 9:00
add a comment |
Use single quotes with double back slash, and you will not get any error.
touch ~/deleted/$(echo "directory_"$(readlink -f foo)|tr '/' '\')
Use single quotes with double back slash, and you will not get any error.
touch ~/deleted/$(echo "directory_"$(readlink -f foo)|tr '/' '\')
edited Aug 28 '17 at 10:07
zagrimsan
694519
694519
answered Aug 28 '17 at 9:12
Tayyab KhanTayyab Khan
211
211
Fun thing is, ifurl=D:ProgramsGitmingw64/share/doc/git-doc/git-log.html
then ``url1=echo $url | tr '\ '/'``` shows the warning, while
url1=$(echo $url | tr '\' '/')` does not.
– ThomasH
Dec 19 '18 at 9:00
add a comment |
Fun thing is, ifurl=D:ProgramsGitmingw64/share/doc/git-doc/git-log.html
then ``url1=echo $url | tr '\ '/'``` shows the warning, while
url1=$(echo $url | tr '\' '/')` does not.
– ThomasH
Dec 19 '18 at 9:00
Fun thing is, if
url=D:ProgramsGitmingw64/share/doc/git-doc/git-log.html
then ``url1=echo $url | tr '\ '/'``` shows the warning, while
url1=$(echo $url | tr '\' '/')` does not.– ThomasH
Dec 19 '18 at 9:00
Fun thing is, if
url=D:ProgramsGitmingw64/share/doc/git-doc/git-log.html
then ``url1=echo $url | tr '\ '/'``` shows the warning, while
url1=$(echo $url | tr '\' '/')` does not.– ThomasH
Dec 19 '18 at 9:00
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%2f148761%2fhow-do-i-suppress-stderr-warning-messages-from-a-command-inside-command-substitu%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
Please edit and clarify how you use this. Are you calling it as a function? Where is
$1
defined? You should also be aware that while– terdon♦
Aug 6 '14 at 14:37
It's in a script. to run it I "sh script nameOfDirectory"
– lonewarrior556
Aug 6 '14 at 14:38
3
Please edit your question to clarify accordingly. I also strongly suggest you consider using any other character but
– terdon♦
Aug 6 '14 at 14:39