Page 1 of 3 123 LastLast
Results 1 to 10 of 23

Thread: Bash Tee function in C code

  1. #1

    Default Bash Tee function in C code

    I can manually create a Bash TEE function in C.

    Is there a TEE function in C already created? Part of the linux kernel or an additional library.


    Thanks.

  2. #2
    Join Date
    Sep 2012
    Posts
    5,977

    Default Re: Bash Tee function in C code

    Quote Originally Posted by lord_valarian View Post
    Bash TEE function
    I have no idea what you are talking about. If you mean tee command (this is tee, not Tee and not TEE) - it has absolutely nothing to do with bash.

    You need to learn to ask your questions so that others have chance to understand them.

  3. #3

    Default Re: Bash Tee function in C code

    Quote Originally Posted by arvidjaar View Post
    I have no idea what you are talking about. If you mean tee command (this is tee, not Tee and not TEE) - it has absolutely nothing to do with bash.

    You need to learn to ask your questions so that others have chance to understand them.
    'tee' function in bash. That's not clear?? OK


    https://linux.die.net/man/1/tee

    Code:
                printf "%s\n" $ScanLine | tee -a "${Current_Vault_Folder}/scanresults.log"

  4. #4
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    27,341

    Default Re: Bash Tee function in C code

    Quote Originally Posted by lord_valarian View Post
    'tee' function in bash. That's not clear?? OK


    https://linux.die.net/man/1/tee

    Code:
                printf "%s\n" $ScanLine | tee -a "${Current_Vault_Folder}/scanresults.log"
    tee is NOT a function in bash:
    Code:
    henk@boven:~> which tee
    /usr/bin/tee
    henk@boven:~>
    it is a program.

    And yes, it has a man page on your very own system(s). No need to go elsewhere for that.
    Code:
    man tee
    Specialy because the one on your system doubtles belongs to the version of the program on your system, which is not sure for the versions of the man page you find on the net.

    I hope you will not catagorize all programs that can be started and thus called from a shell command line and thus also from a bash shell command line a bash function. Then you will be wide beyond what others understand when you talk about "the bash function firefox" (and you certainly loose all contact with reality when you say "the bash function FIREFOX").
    Henk van Velden

  5. #5
    Join Date
    Sep 2012
    Posts
    5,977

    Default Re: Bash Tee function in C code

    Quote Originally Posted by lord_valarian View Post
    There is no similar implementation in standard C library. You could simply open file and duplicate output there. There could be projects that implement high level log wrappers with support for multiple output streams; google is your friend. There are also various toolkits (like glib) that also include log wrappers.

  6. #6

    Default Re: Bash Tee function in C code

    Quote Originally Posted by hcvv View Post
    tee is NOT a function in bash:
    Code:
    henk@boven:~> which tee
    /usr/bin/tee
    henk@boven:~>
    it is a program.

    And yes, it has a man page on your very own system(s). No need to go elsewhere for that.
    Code:
    man tee
    Specially because the one on your system doubles belongs to the version of the program on your system, which is not sure for the versions of the man page you find on the net.

    I hope you will not categorize all programs that can be started and thus called from a shell command line and thus also from a bash shell command line a bash function. Then you will be way beyond what others understand when you talk about "the bash function firefox" (and you certainly loose all contact with reality when you say "the bash function FIREFOX").
    Now that's "splitting hairs" with definitions.

    So, what defines a command line function vs a bash function? What is the difference between a bash function and a command line function?

    Linux has builtin functions and you can extend them with installing libraries. Then install programs adding more command line functions. You can even run 'yast' on the command line. It starts a text based yast.

    'printf' can be used in bash script code and on the command line. Is printf a bash function?

  7. #7
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    27,341

    Default Re: Bash Tee function in C code

    Quote Originally Posted by lord_valarian View Post
    Now that's "splitting hairs" with definitions.

    So, what defines a command line function vs a bash function? What is the difference between a bash function and a command line function?

    Linux has builtin functions and you can extend them with installing libraries. Then install programs adding more command line functions. You can even run 'yast' on the command line. It starts a text based yast.

    'printf' can be used in bash script code and on the command line. Is printf a bash function?
    This all rather stupid talking. Working with computers is of course "splitting hairs", else you will end up in a mess.

    Most of the above is messy and I will not go and comment on all the expressions you use there. I will only answer about the last line where you are again asking without trying to find out yourself first. Use
    Code:
    man bash
    and you will find printf under the SHELL BUILTIN COMMANDS. Thus yes, when you use printf on the bash command line, you are using a bash shell builtin command.
    And before you go wild, this is NOT THE SAME printf as used in the C language.
    Henk van Velden

  8. #8
    Join Date
    Sep 2012
    Location
    Montreal Canada
    Posts
    72

    Default Re: Bash Tee function in C code

    Here is a code fragment;

    #include <stdio.h>

    ...
    FILE *f1, *f2;

    f1=stdout;
    f2=fopen("where_you_want_it/name_of_output",w);

    tee(char *string)
    {
    fprintf(f1,"%s\n",string);
    fprintf(f2,"%s\n",string);
    }

    In your program

    tee( "Hello World");


    // at end of main program
    fclose (f2);
    return 0;
    }

  9. #9
    Join Date
    Sep 2012
    Posts
    5,977

    Default Re: Bash Tee function in C code

    Quote Originally Posted by hcvv View Post
    when you use printf on the bash command line, you are using a bash shell builtin command.
    Never say "never" ...
    Code:
    bor@bor-Latitude-E5450:~$ which printf
    /usr/bin/printf
    bor@bor-Latitude-E5450:~$

  10. #10
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    27,341

    Default Re: Bash Tee function in C code

    Quote Originally Posted by arvidjaar View Post
    Never say "never" ...
    Code:
    bor@bor-Latitude-E5450:~$ which printf
    /usr/bin/printf
    bor@bor-Latitude-E5450:~$
    But when you use printf from bash (as I said):
    Code:
    henk@boven:~> LANG=C type printf
    printf is a shell builtin
    henk@boven:~>
    So you really must use the full path to get that binary executable and hat is not what the OP suggested.

    But it illustrates that there are at least three printf implementations (bash shell builtin, binary executable, C function) and probably they all three try to do the same (let us hope).
    Last edited by hcvv; 29-Aug-2020 at 09:45.
    Henk van Velden

Page 1 of 3 123 LastLast

Tags for this Thread

Posting Permissions

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