Find the answer to your Linux question:
Results 1 to 4 of 4
Hi. The last command in the bash code below gives output I did not expect. Code: daan@schmauck:~/tst$ ls abc abc.sfv abx.sfv sfvsort daan@schmauck:~/tst$ ls | tail -n1 sfvsort daan@schmauck:~/tst$ cksfv ...
  1. #1
    Linux User Daan's Avatar
    Join Date
    Aug 2005
    Location
    The Netherlands
    Posts
    320

    Question cksfv prints output, but it cannot be 'caught'

    Hi.

    The last command in the bash code below gives output I did not expect.

    Code:
    daan@schmauck:~/tst$ ls
    abc  abc.sfv  abx.sfv  sfvsort
    daan@schmauck:~/tst$ ls | tail -n1
    sfvsort
    daan@schmauck:~/tst$ cksfv -f abc.sfv
    --( Verifying: abc.sfv )--------------------------------------------------------
    abc                                               OK
    --------------------------------------------------------------------------------
    Everything OK
    daan@schmauck:~/tst$ cksfv -f abc.sfv | tail -n1
    --( Verifying: abc.sfv )--------------------------------------------------------
    abc                                               OK
    --------------------------------------------------------------------------------
    Everything OK
    daan@schmauck:~/tst$
    I expected there the out put to be
    Code:
    Everything OK
    , just like the output of the second command is only one line. I've also tried saving the output of the last command to a variable:

    Code:
    daan@schmauck:~/tst$ result=$(cksfv -f abc.sfv | tail -n1)
    --( Verifying: abc.sfv )--------------------------------------------------------
    abc                                               OK
    --------------------------------------------------------------------------------
    Everything OK
    daan@schmauck:~/tst$ echo $result
    
    daan@schmauck:~/tst$
    The variable is empty! What is going on here?

  2. #2
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    It seems that your command outputs his messages to stderr.
    Redirects stderr to stdout and see what happens:

    Code:
    2>&1 cksfv -f abc.sfv | tail -n1
    Regards

  3. #3
    Linux User Daan's Avatar
    Join Date
    Aug 2005
    Location
    The Netherlands
    Posts
    320

    Everything OK

    Code:
    daan@schmauck:~/tst$ 2>&1 cksfv -f abc.sfv | tail -n1
    Everything OK
    Thanks.

    Can you explain what it does?

  4. #4
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    To understand how it works you can have a read of section 8.2.3 of this document:

    http://tldp.org/LDP/Bash-Beginners-G...ers-Guide.html

    Regards

Posting Permissions

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