For a single script redirecting stdout and stderr to a file with this:

./myscript.sh 2>&1 | tee -a out_file

works fine. When I try to run the same way a script containing multiple dialog boxes created with dialog command (and calling other scripts)

./main.sh 2>&1 | tee -a out_file

the out_file contains unwanted characters due to these boxes. For example:

# myscript.sh

dialog --title "Title" \
--msgbox "Message Box" \
30 120

generates with:

$ ./myscript.sh 2>&1 | tee -a myscript.out

multiple lines similar to this one:

[36m[44m  [30m[40m[K[22;38H[39;49m(B[m[2;3H[30m[47mMessage Box[22;38H[39;49m(B[m

How can I get stdout and stderr without these characters (for main and all subsequent scripts)? That would be in the example the output of date. Nice to have would be what a user has entered in an inputbox.

  • you could use tr to get rid of it like tr -d 'ﮛ' so maybe like ./main.sh 2>&1 | tr -d 'ﮛ' | tee -a out_file – barlop Apr 6 '18 at 17:55
  • We need details of the scripts and the unwanted characters. Please expand your question to include them. – AFH Apr 6 '18 at 18:00
  • Try using dialog --stdout option, dialog --stdout ... – Paulo Apr 7 '18 at 5:15

You're trying to log color-coded output into a file. See colors and formatting in bash: https://misc.flogisoft.com/bash/tip_colors_and_formatting

You can not arbitrarily change the stdout in this case. Because if you optimize the stdout for logging, then you also change the output wath the users sees.

But you have some possibilities:

  • The easiest way is to add in your myscript.sh the command echo "Message Box printed" >> myscript.out to record some actions directly in file.

  • You can try ./myscript.sh 2>&1 | sed -e "s/<your regex>//g" | tee -a myscript.out and replace <your regex>. But this change output too. So I think that's not what you're looking for.

  • Or you create your own descriptor in myscript.sh with echo "Exit code: $? Textbox $usertext" 1>&4 and modify the dialog command like this usertext=$(dialog --title "Title" --inputbox "Enter your text:" 30 120 "My Text" 3>&1 1>&2 2>&3) Then you can use . myscript.sh 4>> myscript.out

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.