Display output of $() execution [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I have the command below that I used to run without $(), but I have to in order to capture the return code of the remote script. The issue is that now I don't see the command output unless I cat it. Can I see the output during execution?



set -o pipefail
COMMAND=$(ssh $RMT_HOST $RMT_DIR/$SCRIPT_NAME $ARGUMENTS < /dev/null |& tee -a $RMT_EXEC_LOG)
RETCODE=$?


EDIT
Just to clear why I use $() here is a link







share|improve this question














closed as unclear what you're asking by muru, Hauke Laging, Nir, Wouter Verhelst, Archemar Apr 3 at 14:18


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 4




    The usage of $() does not affect the return code...
    – Hauke Laging
    Apr 2 at 15:22










  • Seconding that, you don't have to use command substitution to use $?.
    – muru
    Apr 2 at 15:29






  • 2




    $? is going to contain the return code of tee, not ssh. Use $PIPESTATUS[0].
    – jordanm
    Apr 2 at 15:30






  • 2




    @jordanm this is way I use set -o pipefail
    – Nir
    Apr 2 at 15:38










  • Your link doesn't explain why you use command substitution. If anything, the question itself makes it clear in the beginning that $? works fine without command substitution.
    – muru
    Apr 2 at 15:43














up vote
0
down vote

favorite












I have the command below that I used to run without $(), but I have to in order to capture the return code of the remote script. The issue is that now I don't see the command output unless I cat it. Can I see the output during execution?



set -o pipefail
COMMAND=$(ssh $RMT_HOST $RMT_DIR/$SCRIPT_NAME $ARGUMENTS < /dev/null |& tee -a $RMT_EXEC_LOG)
RETCODE=$?


EDIT
Just to clear why I use $() here is a link







share|improve this question














closed as unclear what you're asking by muru, Hauke Laging, Nir, Wouter Verhelst, Archemar Apr 3 at 14:18


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 4




    The usage of $() does not affect the return code...
    – Hauke Laging
    Apr 2 at 15:22










  • Seconding that, you don't have to use command substitution to use $?.
    – muru
    Apr 2 at 15:29






  • 2




    $? is going to contain the return code of tee, not ssh. Use $PIPESTATUS[0].
    – jordanm
    Apr 2 at 15:30






  • 2




    @jordanm this is way I use set -o pipefail
    – Nir
    Apr 2 at 15:38










  • Your link doesn't explain why you use command substitution. If anything, the question itself makes it clear in the beginning that $? works fine without command substitution.
    – muru
    Apr 2 at 15:43












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have the command below that I used to run without $(), but I have to in order to capture the return code of the remote script. The issue is that now I don't see the command output unless I cat it. Can I see the output during execution?



set -o pipefail
COMMAND=$(ssh $RMT_HOST $RMT_DIR/$SCRIPT_NAME $ARGUMENTS < /dev/null |& tee -a $RMT_EXEC_LOG)
RETCODE=$?


EDIT
Just to clear why I use $() here is a link







share|improve this question














I have the command below that I used to run without $(), but I have to in order to capture the return code of the remote script. The issue is that now I don't see the command output unless I cat it. Can I see the output during execution?



set -o pipefail
COMMAND=$(ssh $RMT_HOST $RMT_DIR/$SCRIPT_NAME $ARGUMENTS < /dev/null |& tee -a $RMT_EXEC_LOG)
RETCODE=$?


EDIT
Just to clear why I use $() here is a link









share|improve this question













share|improve this question




share|improve this question








edited Apr 2 at 15:36

























asked Apr 2 at 15:19









Nir

40121018




40121018




closed as unclear what you're asking by muru, Hauke Laging, Nir, Wouter Verhelst, Archemar Apr 3 at 14:18


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.






closed as unclear what you're asking by muru, Hauke Laging, Nir, Wouter Verhelst, Archemar Apr 3 at 14:18


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









  • 4




    The usage of $() does not affect the return code...
    – Hauke Laging
    Apr 2 at 15:22










  • Seconding that, you don't have to use command substitution to use $?.
    – muru
    Apr 2 at 15:29






  • 2




    $? is going to contain the return code of tee, not ssh. Use $PIPESTATUS[0].
    – jordanm
    Apr 2 at 15:30






  • 2




    @jordanm this is way I use set -o pipefail
    – Nir
    Apr 2 at 15:38










  • Your link doesn't explain why you use command substitution. If anything, the question itself makes it clear in the beginning that $? works fine without command substitution.
    – muru
    Apr 2 at 15:43












  • 4




    The usage of $() does not affect the return code...
    – Hauke Laging
    Apr 2 at 15:22










  • Seconding that, you don't have to use command substitution to use $?.
    – muru
    Apr 2 at 15:29






  • 2




    $? is going to contain the return code of tee, not ssh. Use $PIPESTATUS[0].
    – jordanm
    Apr 2 at 15:30






  • 2




    @jordanm this is way I use set -o pipefail
    – Nir
    Apr 2 at 15:38










  • Your link doesn't explain why you use command substitution. If anything, the question itself makes it clear in the beginning that $? works fine without command substitution.
    – muru
    Apr 2 at 15:43







4




4




The usage of $() does not affect the return code...
– Hauke Laging
Apr 2 at 15:22




The usage of $() does not affect the return code...
– Hauke Laging
Apr 2 at 15:22












Seconding that, you don't have to use command substitution to use $?.
– muru
Apr 2 at 15:29




Seconding that, you don't have to use command substitution to use $?.
– muru
Apr 2 at 15:29




2




2




$? is going to contain the return code of tee, not ssh. Use $PIPESTATUS[0].
– jordanm
Apr 2 at 15:30




$? is going to contain the return code of tee, not ssh. Use $PIPESTATUS[0].
– jordanm
Apr 2 at 15:30




2




2




@jordanm this is way I use set -o pipefail
– Nir
Apr 2 at 15:38




@jordanm this is way I use set -o pipefail
– Nir
Apr 2 at 15:38












Your link doesn't explain why you use command substitution. If anything, the question itself makes it clear in the beginning that $? works fine without command substitution.
– muru
Apr 2 at 15:43




Your link doesn't explain why you use command substitution. If anything, the question itself makes it clear in the beginning that $? works fine without command substitution.
– muru
Apr 2 at 15:43










1 Answer
1






active

oldest

votes

















up vote
1
down vote













If the question you're actually asking is "how can I both capture and display the output of a process?", you're on the right track with tee, but as others have noted, if you later look at the exit code by inspecting $?, you will be getting the exit code of tee and not of the command run through it.



It's easy to store the output and look at it later, but you need to capture the exit code immediately. Better, then, to use a temporary file and handle the output separately:



scratch="$(mktemp)"
trap 'rm -fr "$scratch"' EXIT
--SOME LONG COMMAND-- > "$scratch"
returncode=$?
--HANDLER FOR RETURNCODE--
cat "$scratch" >> /path/to/persistent_logfile





share|improve this answer



























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    If the question you're actually asking is "how can I both capture and display the output of a process?", you're on the right track with tee, but as others have noted, if you later look at the exit code by inspecting $?, you will be getting the exit code of tee and not of the command run through it.



    It's easy to store the output and look at it later, but you need to capture the exit code immediately. Better, then, to use a temporary file and handle the output separately:



    scratch="$(mktemp)"
    trap 'rm -fr "$scratch"' EXIT
    --SOME LONG COMMAND-- > "$scratch"
    returncode=$?
    --HANDLER FOR RETURNCODE--
    cat "$scratch" >> /path/to/persistent_logfile





    share|improve this answer
























      up vote
      1
      down vote













      If the question you're actually asking is "how can I both capture and display the output of a process?", you're on the right track with tee, but as others have noted, if you later look at the exit code by inspecting $?, you will be getting the exit code of tee and not of the command run through it.



      It's easy to store the output and look at it later, but you need to capture the exit code immediately. Better, then, to use a temporary file and handle the output separately:



      scratch="$(mktemp)"
      trap 'rm -fr "$scratch"' EXIT
      --SOME LONG COMMAND-- > "$scratch"
      returncode=$?
      --HANDLER FOR RETURNCODE--
      cat "$scratch" >> /path/to/persistent_logfile





      share|improve this answer






















        up vote
        1
        down vote










        up vote
        1
        down vote









        If the question you're actually asking is "how can I both capture and display the output of a process?", you're on the right track with tee, but as others have noted, if you later look at the exit code by inspecting $?, you will be getting the exit code of tee and not of the command run through it.



        It's easy to store the output and look at it later, but you need to capture the exit code immediately. Better, then, to use a temporary file and handle the output separately:



        scratch="$(mktemp)"
        trap 'rm -fr "$scratch"' EXIT
        --SOME LONG COMMAND-- > "$scratch"
        returncode=$?
        --HANDLER FOR RETURNCODE--
        cat "$scratch" >> /path/to/persistent_logfile





        share|improve this answer












        If the question you're actually asking is "how can I both capture and display the output of a process?", you're on the right track with tee, but as others have noted, if you later look at the exit code by inspecting $?, you will be getting the exit code of tee and not of the command run through it.



        It's easy to store the output and look at it later, but you need to capture the exit code immediately. Better, then, to use a temporary file and handle the output separately:



        scratch="$(mktemp)"
        trap 'rm -fr "$scratch"' EXIT
        --SOME LONG COMMAND-- > "$scratch"
        returncode=$?
        --HANDLER FOR RETURNCODE--
        cat "$scratch" >> /path/to/persistent_logfile






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Apr 2 at 16:53









        DopeGhoti

        40.2k54779




        40.2k54779












            Popular posts from this blog

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

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?