We have updated our Terms of Service, Code of Conduct, and Addendum.

Are some limitations of using tee functions?

E.g. I would like use subshell like $(date). Is it possible?

Best Answer

  • Brendan Dalpe
    Brendan Dalpe Posts: 201 mod
    Answer ✓

    Did a little digging on this. The native function does not spawn a shell, so subshells are not supported.

    However, you can customize your tee function to start a new bash shell which will allow you to run a subshell command as you want.

    The file is written as expected:

    Note: You might not see file timestamp rotation because we're keeping that shell open unless it exits for some reason. Just keep that in mind as you're building out the pipeline.

Answers

  • Brendan Dalpe
    Brendan Dalpe Posts: 201 mod

    Hi @Pawel Kwiatkowski, can you describe the outcome you are trying to achieve? You should be able to use a subshell if the interpreter supports it.

  • Hello @Brendan Dalpe
    I would like redirect output to a log, eg. /tmp/file_$(date "+%d%h%g").log
    When I was using this in the tee fun is not working as expected.

    I was trying using '-a' arg but also is not working.

  • Brendan Dalpe
    Brendan Dalpe Posts: 201 mod
    Answer ✓

    Did a little digging on this. The native function does not spawn a shell, so subshells are not supported.

    However, you can customize your tee function to start a new bash shell which will allow you to run a subshell command as you want.

    The file is written as expected:

    Note: You might not see file timestamp rotation because we're keeping that shell open unless it exits for some reason. Just keep that in mind as you're building out the pipeline.