I want to capture into my bash script (in a variable) the output of some command that prints its output to terminal. I have tried the following:
TEST_OUT=`the_command ARG1` #Nope
#Putting the line "the_command ARG1" into a separate script, testing2.sh,
TEST_OUT=$(./testing2.sh) #Nope
testing2.sh
TEST_OUT=$? #Nope
I am 100% sure that when I run...
> the_command ARG1
...in a terminal, it prints to the terminal exactly the information I want to capture.
Thank you for any help!
You can direct output from a program to your terminal by issuing the ALLOCATE command and substituting an asterisk (*) for a data set name.
the shortcut is Ctrl + Shift + S ; it allows the output to be saved as a text file, or as HTML including colors!
The append >> operator adds the output to the existing content instead of overwriting it. This allows you to redirect the output from multiple commands to a single file. For example, I could redirect the output of date by using the > operator and then redirect hostname and uname -r to the specifications.
If the output is being sent to stderr, you'll need to redirect that to stdout before it can be capture in your var. Try:
TEST_OUT=$(the_command ARG1 2>&1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With