Find the answer to your Linux question:
Results 1 to 3 of 3
Hi there, I am always confused about the redirection operator < Lets say i have a file input.txt that contains one word "hello" without the quotes when i do the ...
  1. #1
    Just Joined!
    Join Date
    Apr 2011
    Posts
    8

    redirection from a file to command

    Hi there,

    I am always confused about the redirection operator <

    Lets say i have a file input.txt that contains one word "hello" without the quotes

    when i do the following why don't i see any output?

    $echo < input.txt



    Secondly, i am slightly confused between input redirection < and pipe | operator. Sometimes they seem to do the same thing. For example i can achieve the output from the above command as follows

    $ cat input.txt | xargs echo


    Can somebody clarify with the help of examples?

    Thanks a lot

  2. #2
    Linux Engineer hazel's Avatar
    Join Date
    May 2004
    Location
    Harrow, UK
    Posts
    955
    The echo command needs an argument (i.e. it has to be told what to echo). There are some commands which can take data from standard input and therefore from a file but echo is not one of them. So echo hello will work and so will echo `cat input.txt` but input.txt<echo will not.

    A redirection operator is used between a program and a file; it causes one of the standard channels (standard input, standard output or standard error) to be replaced by that file. A pipe can only be used between programs; it links the standard output of the first program to the standard input of the second. xargs is a program, which is why your pipe example works.
    "I'm just a little old lady; don't try to dazzle me with jargon!"

  3. #3
    Just Joined!
    Join Date
    Apr 2011
    Posts
    8

    Thanks Hazel

    so nice of you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...