Is such redirection “|>” just an error or it means something?

The name of the pictureThe name of the pictureThe name of the pictureClash 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)










share|improve this question

















  • 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















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)










share|improve this question

















  • 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













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)










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Sep 25 at 8:20









Bdimych2 Bdimych2

462




462







  • 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













  • 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








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











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





share|improve this answer





























    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]$





    share|improve this answer






















    • Funny. Zsh has a different behavior: after the command, my_file contains the output of date.
      – Najib Idrissi
      Sep 25 at 9:28






    • 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











    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: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    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






























    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





    share|improve this answer


























      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





      share|improve this answer
























        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





        share|improve this answer














        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






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Sep 29 at 13:11









        Jeff Schaller

        33.3k850112




        33.3k850112










        answered Sep 25 at 8:26









        ilkkachu

        52.5k679145




        52.5k679145






















            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]$





            share|improve this answer






















            • Funny. Zsh has a different behavior: after the command, my_file contains the output of date.
              – Najib Idrissi
              Sep 25 at 9:28






            • 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















            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]$





            share|improve this answer






















            • Funny. Zsh has a different behavior: after the command, my_file contains the output of date.
              – Najib Idrissi
              Sep 25 at 9:28






            • 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













            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]$





            share|improve this answer














            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]$






            share|improve this answer














            share|improve this answer



            share|improve this answer








            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 of date.
              – Najib Idrissi
              Sep 25 at 9:28






            • 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

















            • Funny. Zsh has a different behavior: after the command, my_file contains the output of date.
              – Najib Idrissi
              Sep 25 at 9:28






            • 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
















            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


















             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            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













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Christian Cage

            How to properly install USB display driver for Fresco Logic FL2000DX on Ubuntu?