Shell command output to file with command being executed [duplicate]How can I save the command and its...
tikz bug in curve to from nodes
Unsolved Problems due to Lack of Computational Power
How does the Saturn V Dynamic Test Stand work?
Earliest evidence of objects intended for future archaeologists?
How to translate 脑袋短路 into English?
What is the grammatical function of the word "y" in the following sentence?
How can I override the serving of Media Files? (Implementing authentication for media items)
Why the color Red in Us, what is the significance?
Starships without computers?
Use of vor in this sentence
Can I submit a paper computer science conference using an alias if using my real name can cause legal trouble in my original country
Does banks' profitability really suffer under low interest rates
Symlink to directory for easy access: .bashrc, usr/local/bin, something else?
How can I pack my food so it doesn't smell?
Are objects subject to critical hits?
Has there ever been a truly bilingual country prior to the contemporary period?
Is recepted a word?
My two team members in a remote location don't get along with each other; how can I improve working relations?
What is "super" in superphosphate?
Double helix Assembly
Output with the same length always
Are unaudited server logs admissible in a court of law?
Is there any road between the CA State Route 120 and Sherman Pass Road (Forest Route 22S0) that crosses Yosemite/Serria/Sequoia National Park/Forest?
Syncing bitcoin node with multiple cores
Shell command output to file with command being executed [duplicate]
How can I save the command and its execution output to file at the same timehow to output text to both screen and file inside a shell script?tail program output to file in Linuxbash shell - ssh remote script capture output and exit code?How to capture error message from executed command?How can I see the exact command line being executed inside some bash instance?Redirect script output to /dev/tty1 and also capture output to fileWrite bash_history to a file with a timestampHow can I capture screen output to a named file on a command by command bases?Improve awk command processing fileRedirecting streams in bash shell - how to make unconditional on the rest of shell command line
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
This question already has an answer here:
How can I save the command and its execution output to file at the same time
4 answers
How can I output the command itself in addition to its output to a file?
I know that I can do how to output text to both screen and file inside a shell script? to capture the output. My use case is specific to pytest.
pytest /awesome_tests -k test_quick_tests -n auto &> test_output_$(date -u +"%FT%H%MZ").txt
It would be really helpful to have the command executed in the output so I knew specifically what the results were for.
linux bash io-redirection
New contributor
Ryan Gates is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
marked as duplicate by Kusalananda♦
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
2 days ago
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
How can I save the command and its execution output to file at the same time
4 answers
How can I output the command itself in addition to its output to a file?
I know that I can do how to output text to both screen and file inside a shell script? to capture the output. My use case is specific to pytest.
pytest /awesome_tests -k test_quick_tests -n auto &> test_output_$(date -u +"%FT%H%MZ").txt
It would be really helpful to have the command executed in the output so I knew specifically what the results were for.
linux bash io-redirection
New contributor
Ryan Gates is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
marked as duplicate by Kusalananda♦
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
2 days ago
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
How can I save the command and its execution output to file at the same time
4 answers
How can I output the command itself in addition to its output to a file?
I know that I can do how to output text to both screen and file inside a shell script? to capture the output. My use case is specific to pytest.
pytest /awesome_tests -k test_quick_tests -n auto &> test_output_$(date -u +"%FT%H%MZ").txt
It would be really helpful to have the command executed in the output so I knew specifically what the results were for.
linux bash io-redirection
New contributor
Ryan Gates is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
This question already has an answer here:
How can I save the command and its execution output to file at the same time
4 answers
How can I output the command itself in addition to its output to a file?
I know that I can do how to output text to both screen and file inside a shell script? to capture the output. My use case is specific to pytest.
pytest /awesome_tests -k test_quick_tests -n auto &> test_output_$(date -u +"%FT%H%MZ").txt
It would be really helpful to have the command executed in the output so I knew specifically what the results were for.
This question already has an answer here:
How can I save the command and its execution output to file at the same time
4 answers
linux bash io-redirection
linux bash io-redirection
New contributor
Ryan Gates is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Ryan Gates is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Ryan Gates is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 2 days ago
Ryan GatesRyan Gates
1064 bronze badges
1064 bronze badges
New contributor
Ryan Gates is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Ryan Gates is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
marked as duplicate by Kusalananda♦
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
2 days ago
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Kusalananda♦
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
2 days ago
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Kusalananda♦
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
2 days ago
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Another option, using bash soley for the &> redirection that you started with, but sh-compatible otherwise:
set -- '/awesome_tests' '-k' 'test_quick_tests' '-n' 'auto'
{ printf '%s %sn' 'pytest' "$*";
pytest "$@";
} &> test_output_$(date -u +"%FT%H%MZ").txt
This sets up the positional parameters to contain the arguments to the pytest command; it then runs two commands inside the {} brace grouping:
- print the
pyteststring followed by the concatenation of the arguments by space (the default first character of$IFS) - run the actual
pytestcommand with the given arguments
That brace group is then redirected as before.
add a comment |
sh -v <<< 'pytest /awesome_tests -k test_quick_tests -n auto'
&> test_output_$(date -u +"%FT%H%MZ").txt
sh -v causes sh to echo each command line to stderr, so since you're already capturing stderr to your output file, all that is needed is to use the -v option and to supply sh with the command you wish to run.
Note that in my testing, sh -v -c 'your-command-here' did not work.
echo 'pytest /awesome_tests -k test_quick_tests -n auto' |
sh -v &> test_output_$(date -u +"%FT%H%MZ").txt
does work, but echo ... | is what bash's <<< is for.
1
sh -v -cprobably did not work since the shell had already read the commands (since you used-c). The-vmakes the shell output the commands "as they are read".
– Kusalananda♦
2 days ago
@Kusalananda Yep. Just checked the man page and that is exactly it.
– Jim L.
2 days ago
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Another option, using bash soley for the &> redirection that you started with, but sh-compatible otherwise:
set -- '/awesome_tests' '-k' 'test_quick_tests' '-n' 'auto'
{ printf '%s %sn' 'pytest' "$*";
pytest "$@";
} &> test_output_$(date -u +"%FT%H%MZ").txt
This sets up the positional parameters to contain the arguments to the pytest command; it then runs two commands inside the {} brace grouping:
- print the
pyteststring followed by the concatenation of the arguments by space (the default first character of$IFS) - run the actual
pytestcommand with the given arguments
That brace group is then redirected as before.
add a comment |
Another option, using bash soley for the &> redirection that you started with, but sh-compatible otherwise:
set -- '/awesome_tests' '-k' 'test_quick_tests' '-n' 'auto'
{ printf '%s %sn' 'pytest' "$*";
pytest "$@";
} &> test_output_$(date -u +"%FT%H%MZ").txt
This sets up the positional parameters to contain the arguments to the pytest command; it then runs two commands inside the {} brace grouping:
- print the
pyteststring followed by the concatenation of the arguments by space (the default first character of$IFS) - run the actual
pytestcommand with the given arguments
That brace group is then redirected as before.
add a comment |
Another option, using bash soley for the &> redirection that you started with, but sh-compatible otherwise:
set -- '/awesome_tests' '-k' 'test_quick_tests' '-n' 'auto'
{ printf '%s %sn' 'pytest' "$*";
pytest "$@";
} &> test_output_$(date -u +"%FT%H%MZ").txt
This sets up the positional parameters to contain the arguments to the pytest command; it then runs two commands inside the {} brace grouping:
- print the
pyteststring followed by the concatenation of the arguments by space (the default first character of$IFS) - run the actual
pytestcommand with the given arguments
That brace group is then redirected as before.
Another option, using bash soley for the &> redirection that you started with, but sh-compatible otherwise:
set -- '/awesome_tests' '-k' 'test_quick_tests' '-n' 'auto'
{ printf '%s %sn' 'pytest' "$*";
pytest "$@";
} &> test_output_$(date -u +"%FT%H%MZ").txt
This sets up the positional parameters to contain the arguments to the pytest command; it then runs two commands inside the {} brace grouping:
- print the
pyteststring followed by the concatenation of the arguments by space (the default first character of$IFS) - run the actual
pytestcommand with the given arguments
That brace group is then redirected as before.
answered 2 days ago
Jeff Schaller♦Jeff Schaller
49k11 gold badges72 silver badges162 bronze badges
49k11 gold badges72 silver badges162 bronze badges
add a comment |
add a comment |
sh -v <<< 'pytest /awesome_tests -k test_quick_tests -n auto'
&> test_output_$(date -u +"%FT%H%MZ").txt
sh -v causes sh to echo each command line to stderr, so since you're already capturing stderr to your output file, all that is needed is to use the -v option and to supply sh with the command you wish to run.
Note that in my testing, sh -v -c 'your-command-here' did not work.
echo 'pytest /awesome_tests -k test_quick_tests -n auto' |
sh -v &> test_output_$(date -u +"%FT%H%MZ").txt
does work, but echo ... | is what bash's <<< is for.
1
sh -v -cprobably did not work since the shell had already read the commands (since you used-c). The-vmakes the shell output the commands "as they are read".
– Kusalananda♦
2 days ago
@Kusalananda Yep. Just checked the man page and that is exactly it.
– Jim L.
2 days ago
add a comment |
sh -v <<< 'pytest /awesome_tests -k test_quick_tests -n auto'
&> test_output_$(date -u +"%FT%H%MZ").txt
sh -v causes sh to echo each command line to stderr, so since you're already capturing stderr to your output file, all that is needed is to use the -v option and to supply sh with the command you wish to run.
Note that in my testing, sh -v -c 'your-command-here' did not work.
echo 'pytest /awesome_tests -k test_quick_tests -n auto' |
sh -v &> test_output_$(date -u +"%FT%H%MZ").txt
does work, but echo ... | is what bash's <<< is for.
1
sh -v -cprobably did not work since the shell had already read the commands (since you used-c). The-vmakes the shell output the commands "as they are read".
– Kusalananda♦
2 days ago
@Kusalananda Yep. Just checked the man page and that is exactly it.
– Jim L.
2 days ago
add a comment |
sh -v <<< 'pytest /awesome_tests -k test_quick_tests -n auto'
&> test_output_$(date -u +"%FT%H%MZ").txt
sh -v causes sh to echo each command line to stderr, so since you're already capturing stderr to your output file, all that is needed is to use the -v option and to supply sh with the command you wish to run.
Note that in my testing, sh -v -c 'your-command-here' did not work.
echo 'pytest /awesome_tests -k test_quick_tests -n auto' |
sh -v &> test_output_$(date -u +"%FT%H%MZ").txt
does work, but echo ... | is what bash's <<< is for.
sh -v <<< 'pytest /awesome_tests -k test_quick_tests -n auto'
&> test_output_$(date -u +"%FT%H%MZ").txt
sh -v causes sh to echo each command line to stderr, so since you're already capturing stderr to your output file, all that is needed is to use the -v option and to supply sh with the command you wish to run.
Note that in my testing, sh -v -c 'your-command-here' did not work.
echo 'pytest /awesome_tests -k test_quick_tests -n auto' |
sh -v &> test_output_$(date -u +"%FT%H%MZ").txt
does work, but echo ... | is what bash's <<< is for.
edited 2 days ago
answered 2 days ago
Jim L.Jim L.
1,9194 silver badges10 bronze badges
1,9194 silver badges10 bronze badges
1
sh -v -cprobably did not work since the shell had already read the commands (since you used-c). The-vmakes the shell output the commands "as they are read".
– Kusalananda♦
2 days ago
@Kusalananda Yep. Just checked the man page and that is exactly it.
– Jim L.
2 days ago
add a comment |
1
sh -v -cprobably did not work since the shell had already read the commands (since you used-c). The-vmakes the shell output the commands "as they are read".
– Kusalananda♦
2 days ago
@Kusalananda Yep. Just checked the man page and that is exactly it.
– Jim L.
2 days ago
1
1
sh -v -c probably did not work since the shell had already read the commands (since you used -c). The -v makes the shell output the commands "as they are read".– Kusalananda♦
2 days ago
sh -v -c probably did not work since the shell had already read the commands (since you used -c). The -v makes the shell output the commands "as they are read".– Kusalananda♦
2 days ago
@Kusalananda Yep. Just checked the man page and that is exactly it.
– Jim L.
2 days ago
@Kusalananda Yep. Just checked the man page and that is exactly it.
– Jim L.
2 days ago
add a comment |