Is such redirection “|>†just an error or it means something?
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I typed it by mistake but bash didn't print any errors (but created an empty file) so I thought maybe it actually means something ?
(e.g. date |> tmp.txt)
bash io-redirection
add a comment |Â
up vote
1
down vote
favorite
I typed it by mistake but bash didn't print any errors (but created an empty file) so I thought maybe it actually means something ?
(e.g. date |> tmp.txt)
bash io-redirection
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I typed it by mistake but bash didn't print any errors (but created an empty file) so I thought maybe it actually means something ?
(e.g. date |> tmp.txt)
bash io-redirection
I typed it by mistake but bash didn't print any errors (but created an empty file) so I thought maybe it actually means something ?
(e.g. date |> tmp.txt)
bash io-redirection
bash io-redirection
asked 1 hour ago
Bdimych2 Bdimych2
111
111
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
4
down vote
That seems to be just a pipeline where the second part is an empty command, only containing the redirection. Writing it as date | >file
might make it more easy to interpret. The empty command doesn't do anything but process the redirection, creating the file.
date >| file
on the other hand would act as an override for the noclobber
shell option, which prevents the regular >
from overwriting existing files.
$ touch foo; set -o noclobber
$ date > foo
bash: foo: cannot overwrite existing file
$ date >| foo # works
add a comment |Â
up vote
0
down vote
Yes, it will not throw error because for bash > file
means redirect to a file named file
. As in your case there is nothing to redirect to file, bash will just create a file name file
with nothing in it.
[bd@centos-6.5 my-tests]$ date | > my_file
[bd@centos-6.5 my-tests]$ cat my_file
[bd@centos-6.5 my-tests]$
Funny. Zsh has a different behavior: after the command,my_file
contains the output ofdate
.
– Najib Idrissi
27 secs ago
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
That seems to be just a pipeline where the second part is an empty command, only containing the redirection. Writing it as date | >file
might make it more easy to interpret. The empty command doesn't do anything but process the redirection, creating the file.
date >| file
on the other hand would act as an override for the noclobber
shell option, which prevents the regular >
from overwriting existing files.
$ touch foo; set -o noclobber
$ date > foo
bash: foo: cannot overwrite existing file
$ date >| foo # works
add a comment |Â
up vote
4
down vote
That seems to be just a pipeline where the second part is an empty command, only containing the redirection. Writing it as date | >file
might make it more easy to interpret. The empty command doesn't do anything but process the redirection, creating the file.
date >| file
on the other hand would act as an override for the noclobber
shell option, which prevents the regular >
from overwriting existing files.
$ touch foo; set -o noclobber
$ date > foo
bash: foo: cannot overwrite existing file
$ date >| foo # works
add a comment |Â
up vote
4
down vote
up vote
4
down vote
That seems to be just a pipeline where the second part is an empty command, only containing the redirection. Writing it as date | >file
might make it more easy to interpret. The empty command doesn't do anything but process the redirection, creating the file.
date >| file
on the other hand would act as an override for the noclobber
shell option, which prevents the regular >
from overwriting existing files.
$ touch foo; set -o noclobber
$ date > foo
bash: foo: cannot overwrite existing file
$ date >| foo # works
That seems to be just a pipeline where the second part is an empty command, only containing the redirection. Writing it as date | >file
might make it more easy to interpret. The empty command doesn't do anything but process the redirection, creating the file.
date >| file
on the other hand would act as an override for the noclobber
shell option, which prevents the regular >
from overwriting existing files.
$ touch foo; set -o noclobber
$ date > foo
bash: foo: cannot overwrite existing file
$ date >| foo # works
answered 1 hour ago


ilkkachu
51.4k678141
51.4k678141
add a comment |Â
add a comment |Â
up vote
0
down vote
Yes, it will not throw error because for bash > file
means redirect to a file named file
. As in your case there is nothing to redirect to file, bash will just create a file name file
with nothing in it.
[bd@centos-6.5 my-tests]$ date | > my_file
[bd@centos-6.5 my-tests]$ cat my_file
[bd@centos-6.5 my-tests]$
Funny. Zsh has a different behavior: after the command,my_file
contains the output ofdate
.
– Najib Idrissi
27 secs ago
add a comment |Â
up vote
0
down vote
Yes, it will not throw error because for bash > file
means redirect to a file named file
. As in your case there is nothing to redirect to file, bash will just create a file name file
with nothing in it.
[bd@centos-6.5 my-tests]$ date | > my_file
[bd@centos-6.5 my-tests]$ cat my_file
[bd@centos-6.5 my-tests]$
Funny. Zsh has a different behavior: after the command,my_file
contains the output ofdate
.
– Najib Idrissi
27 secs ago
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Yes, it will not throw error because for bash > file
means redirect to a file named file
. As in your case there is nothing to redirect to file, bash will just create a file name file
with nothing in it.
[bd@centos-6.5 my-tests]$ date | > my_file
[bd@centos-6.5 my-tests]$ cat my_file
[bd@centos-6.5 my-tests]$
Yes, it will not throw error because for bash > file
means redirect to a file named file
. As in your case there is nothing to redirect to file, bash will just create a file name file
with nothing in it.
[bd@centos-6.5 my-tests]$ date | > my_file
[bd@centos-6.5 my-tests]$ cat my_file
[bd@centos-6.5 my-tests]$
edited 13 mins ago
answered 20 mins ago
Bhagyesh Dudhediya
306314
306314
Funny. Zsh has a different behavior: after the command,my_file
contains the output ofdate
.
– Najib Idrissi
27 secs ago
add a comment |Â
Funny. Zsh has a different behavior: after the command,my_file
contains the output ofdate
.
– Najib Idrissi
27 secs ago
Funny. Zsh has a different behavior: after the command,
my_file
contains the output of date
.– Najib Idrissi
27 secs ago
Funny. Zsh has a different behavior: after the command,
my_file
contains the output of date
.– Najib Idrissi
27 secs ago
add a comment |Â
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%2f471258%2fis-such-redirection-just-an-error-or-it-means-something%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