Can I create BASH function that will hold text block that can then be called for output to FILE and SCREEN to cut down on code block repetition [duplicate]
Clash Royale CLAN TAG#URR8PPP
This question already has an answer here:
how to output text to both screen and file inside a shell script?
3 answers
I have a BASH utility that outputs measurements to screen live as it runs and writes the result to file at the same time.
I am having to repeat the same code twice (see below).
Once to write to screen, and
Once to write to file.
This seems like a lot of redundancy to me.
Can I put one text block into something like a function then call it to be written to screen and file at the same time?
This would cut down on a lot of re-keying.
Example below
###### write out to file : push end time at end ################
echo >> $file_name
echo "End time: "$end_time >> $file_name
echo >> $file_name
echo >> $file_name
echo >> $file_name
###### print to screen : push end time at end #################
echo
echo "End time: "$end_time
echo
echo
echo
So I'd be looking for someting like this
funtion text_block
###### print to screen : push end time at end #################
echo
echo "End time: "$end_time
echo
echo
echo
Then a command that does something like this
"command
print text_block
to screen, print text_block
to file"
bash shell-script scripting
marked as duplicate by Kiwy, Rui F Ribeiro, Christopher, roaima, Mr Shunz Jan 16 at 9:06
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 to output text to both screen and file inside a shell script?
3 answers
I have a BASH utility that outputs measurements to screen live as it runs and writes the result to file at the same time.
I am having to repeat the same code twice (see below).
Once to write to screen, and
Once to write to file.
This seems like a lot of redundancy to me.
Can I put one text block into something like a function then call it to be written to screen and file at the same time?
This would cut down on a lot of re-keying.
Example below
###### write out to file : push end time at end ################
echo >> $file_name
echo "End time: "$end_time >> $file_name
echo >> $file_name
echo >> $file_name
echo >> $file_name
###### print to screen : push end time at end #################
echo
echo "End time: "$end_time
echo
echo
echo
So I'd be looking for someting like this
funtion text_block
###### print to screen : push end time at end #################
echo
echo "End time: "$end_time
echo
echo
echo
Then a command that does something like this
"command
print text_block
to screen, print text_block
to file"
bash shell-script scripting
marked as duplicate by Kiwy, Rui F Ribeiro, Christopher, roaima, Mr Shunz Jan 16 at 9:06
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 to output text to both screen and file inside a shell script?
3 answers
I have a BASH utility that outputs measurements to screen live as it runs and writes the result to file at the same time.
I am having to repeat the same code twice (see below).
Once to write to screen, and
Once to write to file.
This seems like a lot of redundancy to me.
Can I put one text block into something like a function then call it to be written to screen and file at the same time?
This would cut down on a lot of re-keying.
Example below
###### write out to file : push end time at end ################
echo >> $file_name
echo "End time: "$end_time >> $file_name
echo >> $file_name
echo >> $file_name
echo >> $file_name
###### print to screen : push end time at end #################
echo
echo "End time: "$end_time
echo
echo
echo
So I'd be looking for someting like this
funtion text_block
###### print to screen : push end time at end #################
echo
echo "End time: "$end_time
echo
echo
echo
Then a command that does something like this
"command
print text_block
to screen, print text_block
to file"
bash shell-script scripting
This question already has an answer here:
how to output text to both screen and file inside a shell script?
3 answers
I have a BASH utility that outputs measurements to screen live as it runs and writes the result to file at the same time.
I am having to repeat the same code twice (see below).
Once to write to screen, and
Once to write to file.
This seems like a lot of redundancy to me.
Can I put one text block into something like a function then call it to be written to screen and file at the same time?
This would cut down on a lot of re-keying.
Example below
###### write out to file : push end time at end ################
echo >> $file_name
echo "End time: "$end_time >> $file_name
echo >> $file_name
echo >> $file_name
echo >> $file_name
###### print to screen : push end time at end #################
echo
echo "End time: "$end_time
echo
echo
echo
So I'd be looking for someting like this
funtion text_block
###### print to screen : push end time at end #################
echo
echo "End time: "$end_time
echo
echo
echo
Then a command that does something like this
"command
print text_block
to screen, print text_block
to file"
This question already has an answer here:
how to output text to both screen and file inside a shell script?
3 answers
bash shell-script scripting
bash shell-script scripting
edited Jan 15 at 13:05
Kiwy
5,97253558
5,97253558
asked Jan 15 at 12:54
KesKes
966
966
marked as duplicate by Kiwy, Rui F Ribeiro, Christopher, roaima, Mr Shunz Jan 16 at 9:06
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 Kiwy, Rui F Ribeiro, Christopher, roaima, Mr Shunz Jan 16 at 9:06
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 |
1 Answer
1
active
oldest
votes
You can use the utility tee
command | tee my_file.out
this will both write a file name my_file.out and write it to stdout.
Source this post from StackOverflow
that really helped me clean up repeat code and get rid of typos introduced by unnecessary re-keying when making changes. Thanks
– Kes
Jan 15 at 13:37
You're very welcome @Kes
– Kiwy
Jan 15 at 14:24
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use the utility tee
command | tee my_file.out
this will both write a file name my_file.out and write it to stdout.
Source this post from StackOverflow
that really helped me clean up repeat code and get rid of typos introduced by unnecessary re-keying when making changes. Thanks
– Kes
Jan 15 at 13:37
You're very welcome @Kes
– Kiwy
Jan 15 at 14:24
add a comment |
You can use the utility tee
command | tee my_file.out
this will both write a file name my_file.out and write it to stdout.
Source this post from StackOverflow
that really helped me clean up repeat code and get rid of typos introduced by unnecessary re-keying when making changes. Thanks
– Kes
Jan 15 at 13:37
You're very welcome @Kes
– Kiwy
Jan 15 at 14:24
add a comment |
You can use the utility tee
command | tee my_file.out
this will both write a file name my_file.out and write it to stdout.
Source this post from StackOverflow
You can use the utility tee
command | tee my_file.out
this will both write a file name my_file.out and write it to stdout.
Source this post from StackOverflow
answered Jan 15 at 12:59
KiwyKiwy
5,97253558
5,97253558
that really helped me clean up repeat code and get rid of typos introduced by unnecessary re-keying when making changes. Thanks
– Kes
Jan 15 at 13:37
You're very welcome @Kes
– Kiwy
Jan 15 at 14:24
add a comment |
that really helped me clean up repeat code and get rid of typos introduced by unnecessary re-keying when making changes. Thanks
– Kes
Jan 15 at 13:37
You're very welcome @Kes
– Kiwy
Jan 15 at 14:24
that really helped me clean up repeat code and get rid of typos introduced by unnecessary re-keying when making changes. Thanks
– Kes
Jan 15 at 13:37
that really helped me clean up repeat code and get rid of typos introduced by unnecessary re-keying when making changes. Thanks
– Kes
Jan 15 at 13:37
You're very welcome @Kes
– Kiwy
Jan 15 at 14:24
You're very welcome @Kes
– Kiwy
Jan 15 at 14:24
add a comment |