Display output of $() execution [closed]
Clash 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
bash shell-script shell
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.
 |Â
show 1 more comment
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
bash shell-script shell
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 oftee
, notssh
. Use$PIPESTATUS[0]
.
â jordanm
Apr 2 at 15:30
2
@jordanm this is way I useset -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
 |Â
show 1 more comment
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
bash shell-script shell
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
bash shell-script shell
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 oftee
, notssh
. Use$PIPESTATUS[0]
.
â jordanm
Apr 2 at 15:30
2
@jordanm this is way I useset -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
 |Â
show 1 more comment
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 oftee
, notssh
. Use$PIPESTATUS[0]
.
â jordanm
Apr 2 at 15:30
2
@jordanm this is way I useset -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
 |Â
show 1 more comment
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
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
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
answered Apr 2 at 16:53
DopeGhoti
40.2k54779
40.2k54779
add a comment |Â
add a comment |Â
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 oftee
, notssh
. 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