Is such redirection â|>â just an error or it means something?
Clash Royale CLAN TAG#URR8PPP
up vote
8
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
8
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
1
Are you sure the command isnâÂÂt of the formdate |> tmp.txt cmd2
? Because that changes the answer.
â Konrad Rudolph
Sep 25 at 13:26
add a comment |Â
up vote
8
down vote
favorite
up vote
8
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 Sep 25 at 8:20
Bdimych2 Bdimych2
462
462
1
Are you sure the command isnâÂÂt of the formdate |> tmp.txt cmd2
? Because that changes the answer.
â Konrad Rudolph
Sep 25 at 13:26
add a comment |Â
1
Are you sure the command isnâÂÂt of the formdate |> tmp.txt cmd2
? Because that changes the answer.
â Konrad Rudolph
Sep 25 at 13:26
1
1
Are you sure the command isnâÂÂt of the form
date |> tmp.txt cmd2
? Because that changes the answer.â Konrad Rudolph
Sep 25 at 13:26
Are you sure the command isnâÂÂt of the form
date |> tmp.txt cmd2
? Because that changes the answer.â Konrad Rudolph
Sep 25 at 13:26
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
17
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 easier 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
1
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
Sep 25 at 9:28
12
@NajibIdrissi, inzsh
, when there are only redirections and no command,zsh
runs the$NULLCMD
command (cat
by default) or$READNULLCMD
(a pager by default) if there are only input redirections.
â Stéphane Chazelas
Sep 25 at 9:34
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
17
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 easier 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
17
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 easier 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
17
down vote
up vote
17
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 easier 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 easier 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
edited Sep 29 at 13:11
Jeff Schaller
33.3k850112
33.3k850112
answered Sep 25 at 8:26
ilkkachu
52.5k679145
52.5k679145
add a comment |Â
add a comment |Â
up vote
1
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
Sep 25 at 9:28
12
@NajibIdrissi, inzsh
, when there are only redirections and no command,zsh
runs the$NULLCMD
command (cat
by default) or$READNULLCMD
(a pager by default) if there are only input redirections.
â Stéphane Chazelas
Sep 25 at 9:34
add a comment |Â
up vote
1
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
Sep 25 at 9:28
12
@NajibIdrissi, inzsh
, when there are only redirections and no command,zsh
runs the$NULLCMD
command (cat
by default) or$READNULLCMD
(a pager by default) if there are only input redirections.
â Stéphane Chazelas
Sep 25 at 9:34
add a comment |Â
up vote
1
down vote
up vote
1
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 Sep 25 at 9:14
answered Sep 25 at 9:07
Bhagyesh Dudhediya
316314
316314
Funny. Zsh has a different behavior: after the command,my_file
contains the output ofdate
.
â Najib Idrissi
Sep 25 at 9:28
12
@NajibIdrissi, inzsh
, when there are only redirections and no command,zsh
runs the$NULLCMD
command (cat
by default) or$READNULLCMD
(a pager by default) if there are only input redirections.
â Stéphane Chazelas
Sep 25 at 9:34
add a comment |Â
Funny. Zsh has a different behavior: after the command,my_file
contains the output ofdate
.
â Najib Idrissi
Sep 25 at 9:28
12
@NajibIdrissi, inzsh
, when there are only redirections and no command,zsh
runs the$NULLCMD
command (cat
by default) or$READNULLCMD
(a pager by default) if there are only input redirections.
â Stéphane Chazelas
Sep 25 at 9:34
Funny. Zsh has a different behavior: after the command,
my_file
contains the output of date
.â Najib Idrissi
Sep 25 at 9:28
Funny. Zsh has a different behavior: after the command,
my_file
contains the output of date
.â Najib Idrissi
Sep 25 at 9:28
12
12
@NajibIdrissi, in
zsh
, when there are only redirections and no command, zsh
runs the $NULLCMD
command (cat
by default) or $READNULLCMD
(a pager by default) if there are only input redirections.â Stéphane Chazelas
Sep 25 at 9:34
@NajibIdrissi, in
zsh
, when there are only redirections and no command, zsh
runs the $NULLCMD
command (cat
by default) or $READNULLCMD
(a pager by default) if there are only input redirections.â Stéphane Chazelas
Sep 25 at 9:34
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
1
Are you sure the command isnâÂÂt of the form
date |> tmp.txt cmd2
? Because that changes the answer.â Konrad Rudolph
Sep 25 at 13:26