For some commands, in the terminal they print with some colors in the stdout, for example:
git status
mvn help:help -Ddetail=true
gradle build
Any Linux command (ls [-...], etc)
Note: it applies for scripts that contain:
- Executions of Linux commands
- Executions for tools commands
- Executions other scripts
Therefore the following is possible:
./mvnw help:help -Ddetail=true
./gradlew build
./customscript.sh
Until nothing is new and all work how is expected, therefore:
- linux_command
- tool_command (maven, git, gradle etc)
script.sh(execute linux/tools commands and other scripts)
So if any of them print in the terminal (stdout) some colors, it is the default behavior according each command/tool
Now if I want see the output in the terminal (as above) and write it to some file, according with:
Therefore is possible do in general
"linux_command" | tee [-a] "/some/path/log_file.log"
"tool_command" | tee [-a] "/some/path/log_file.log"
"script.sh" | tee [-a] "/some/path/log_file.log"
And it works how is expected, but the output in the terminal (stdout) does not include the colors anymore.
Question:
- How to show the output for the execution for any command and/or script in
stdoutand file but keeping the color in thestdout?
Same behaviour when the pipe and tee were not included and of course meanwhile write the content in the .log file.
Note I did do a research about the script command
but it overrides the script.sh content
I need a general approach, it for any command and/or script.sh