Formatting display of of `set -v` output

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











up vote
3
down vote

favorite
1












From the description of set in the bash man page:



-v Print shell input lines as they are read.


Thus, the following example script:



#!/usr/bin/env bash
# setv.sh
set -v
foo=bar
echo $foo


Generates output:



foo=bar
echo $foo
bar


Is there a way for it to prepend some string, say "+ " to each line, so as to clearly indicate which line is a line from the script, and which line is output of a line of from the script. Using the above example, the desired output would be:



+ foo=bar
+ echo $foo
bar






share|improve this question






















  • What do you mean when you say "The output looks like"? What command did you execute to generate that undesirable output?
    – user1404316
    Mar 15 at 20:11










  • I think I now understand what you are looking for. I'll try to edit your question to make it clearer.
    – user1404316
    Mar 15 at 20:21














up vote
3
down vote

favorite
1












From the description of set in the bash man page:



-v Print shell input lines as they are read.


Thus, the following example script:



#!/usr/bin/env bash
# setv.sh
set -v
foo=bar
echo $foo


Generates output:



foo=bar
echo $foo
bar


Is there a way for it to prepend some string, say "+ " to each line, so as to clearly indicate which line is a line from the script, and which line is output of a line of from the script. Using the above example, the desired output would be:



+ foo=bar
+ echo $foo
bar






share|improve this question






















  • What do you mean when you say "The output looks like"? What command did you execute to generate that undesirable output?
    – user1404316
    Mar 15 at 20:11










  • I think I now understand what you are looking for. I'll try to edit your question to make it clearer.
    – user1404316
    Mar 15 at 20:21












up vote
3
down vote

favorite
1









up vote
3
down vote

favorite
1






1





From the description of set in the bash man page:



-v Print shell input lines as they are read.


Thus, the following example script:



#!/usr/bin/env bash
# setv.sh
set -v
foo=bar
echo $foo


Generates output:



foo=bar
echo $foo
bar


Is there a way for it to prepend some string, say "+ " to each line, so as to clearly indicate which line is a line from the script, and which line is output of a line of from the script. Using the above example, the desired output would be:



+ foo=bar
+ echo $foo
bar






share|improve this question














From the description of set in the bash man page:



-v Print shell input lines as they are read.


Thus, the following example script:



#!/usr/bin/env bash
# setv.sh
set -v
foo=bar
echo $foo


Generates output:



foo=bar
echo $foo
bar


Is there a way for it to prepend some string, say "+ " to each line, so as to clearly indicate which line is a line from the script, and which line is output of a line of from the script. Using the above example, the desired output would be:



+ foo=bar
+ echo $foo
bar








share|improve this question













share|improve this question




share|improve this question








edited Mar 15 at 22:04









user1404316

2,314520




2,314520










asked Mar 15 at 20:07









mbigras

5822522




5822522











  • What do you mean when you say "The output looks like"? What command did you execute to generate that undesirable output?
    – user1404316
    Mar 15 at 20:11










  • I think I now understand what you are looking for. I'll try to edit your question to make it clearer.
    – user1404316
    Mar 15 at 20:21
















  • What do you mean when you say "The output looks like"? What command did you execute to generate that undesirable output?
    – user1404316
    Mar 15 at 20:11










  • I think I now understand what you are looking for. I'll try to edit your question to make it clearer.
    – user1404316
    Mar 15 at 20:21















What do you mean when you say "The output looks like"? What command did you execute to generate that undesirable output?
– user1404316
Mar 15 at 20:11




What do you mean when you say "The output looks like"? What command did you execute to generate that undesirable output?
– user1404316
Mar 15 at 20:11












I think I now understand what you are looking for. I'll try to edit your question to make it clearer.
– user1404316
Mar 15 at 20:21




I think I now understand what you are looking for. I'll try to edit your question to make it clearer.
– user1404316
Mar 15 at 20:21










1 Answer
1






active

oldest

votes

















up vote
3
down vote



accepted










To get that kind of output you could use $BASH_COMMAND e.g. add



trap 'printf "%s %sn" + "$BASH_COMMAND" >&2' DEBUG


instead of set -x/v at the top your script.






share|improve this answer






















  • You would probably want to print that on stderr. The OP might also want set -o functrace
    – Stéphane Chazelas
    Mar 15 at 21:33










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f430480%2fformatting-display-of-of-set-v-output%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote



accepted










To get that kind of output you could use $BASH_COMMAND e.g. add



trap 'printf "%s %sn" + "$BASH_COMMAND" >&2' DEBUG


instead of set -x/v at the top your script.






share|improve this answer






















  • You would probably want to print that on stderr. The OP might also want set -o functrace
    – Stéphane Chazelas
    Mar 15 at 21:33














up vote
3
down vote



accepted










To get that kind of output you could use $BASH_COMMAND e.g. add



trap 'printf "%s %sn" + "$BASH_COMMAND" >&2' DEBUG


instead of set -x/v at the top your script.






share|improve this answer






















  • You would probably want to print that on stderr. The OP might also want set -o functrace
    – Stéphane Chazelas
    Mar 15 at 21:33












up vote
3
down vote



accepted







up vote
3
down vote



accepted






To get that kind of output you could use $BASH_COMMAND e.g. add



trap 'printf "%s %sn" + "$BASH_COMMAND" >&2' DEBUG


instead of set -x/v at the top your script.






share|improve this answer














To get that kind of output you could use $BASH_COMMAND e.g. add



trap 'printf "%s %sn" + "$BASH_COMMAND" >&2' DEBUG


instead of set -x/v at the top your script.







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 15 at 21:37

























answered Mar 15 at 21:08









don_crissti

46.4k15123153




46.4k15123153











  • You would probably want to print that on stderr. The OP might also want set -o functrace
    – Stéphane Chazelas
    Mar 15 at 21:33
















  • You would probably want to print that on stderr. The OP might also want set -o functrace
    – Stéphane Chazelas
    Mar 15 at 21:33















You would probably want to print that on stderr. The OP might also want set -o functrace
– Stéphane Chazelas
Mar 15 at 21:33




You would probably want to print that on stderr. The OP might also want set -o functrace
– Stéphane Chazelas
Mar 15 at 21:33












 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f430480%2fformatting-display-of-of-set-v-output%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

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

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay