Is it possible to redirect bash -v output?

starting bash with the -v option gives long output to the console

$ bash -v source ~/Dropbox/bin/tim_functions.sh \#!/bin/bash ...several hundred more lines 

I would like to write the output to a file to make browsing easier, but I tried bash -v 2>&1 > out_bash.txt and bash -v | tee out_bash.txt bash -v | tee out_bash.txt and could not capture the information on the terminal screen in a file. It is as if the voluminous output was neither stderr nor stdout. How can it be?

Can anyone suggest a way to capture the output of bash -v?

+6
source share
6 answers

After reading other useful answers, I believe this problem is related to the way bash sends detailed information to tty, which is somewhat different from stderr or stdout. It can be caught with the following work:

 $ screen -L $ bash -v $ exit #from the bash session $ exit #from the screen session 

This results in the creation of a screenlog.0 file containing the output.

Interest in bash -v was of interest on a Mac running 10.7.3 (Lion) with

 $ bash --version GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin11) Copyright (C) 2007 Free Software Foundation, Inc.) 

The other 10.6.8 mac I tried had less (interesting / verbose) output, despite a similar .bashrc file.

+1
source
  bash -v 2>&1 > out_bash.txt 

not what you want, it should be

  bash -v >out_bash.txt 2>&1 
+6
source

I poked and found this http://www.commandlinefu.com/commands/view/3310/run-a-bash-script-in-debug-mode-show-output-and-save-it-on-a-file

On the website they use bash -x test.sh 2>&1 | tee out.test bash -x test.sh 2>&1 | tee out.test , but I tested it with bash -v test.sh 2>&1 | tee out.test bash -v test.sh 2>&1 | tee out.test and it worked fine.

+4
source

you can also use the exec command in a script to redirect all output:

 #!/bin/bash exec >> out.txt 2>> out.txt set -x set -v echo "testing debug of shell scripts" ls 
+3
source

Have you tried wrapping your baby bash in a subshell?

 ( bash -v ) 2>&1 > out_bash.txt 
0
source

You can use, bash -v 2> & 1 | tee file.txt or bash -v 2> & 1 | grep search_string

0
source

Source: https://habr.com/ru/post/918724/


All Articles