1

I have a fairly complex piece of bash script to run through different configurations and install lots of Oracle schemas, during which I got to call "liquibase" which is a piece of java software.

What I want to do is completely silence the output from liquibase and handle these outputs conditionally depending on the output.

I try doing this with following way

#!/bin/bash
output=$(liquibase --"lots of parameters here") > /dev/null 2> /dev/null
echo "from the variable:$output"

which does same "some" part of the output, into my variable but still displays some other part on the screen. For example I get:

Liquibase 'status' Successful
from the variable:PROCESS10@jdbc:oracle:thin:@localhost is up to date

As you can see "Liquibase 'status' Successful" is not saved in my variable and written directly to screen.

So how can I redirect/save all output into a variable instead of dumping it to screen?

kali
  • 1,143
  • 1
  • 9
  • 26

1 Answers1

3

The problem is in:

output=$(liquibase --"lots of parameters here") > /dev/null 2> /dev/null

The STDOUT and STDERR redirections become useless when you say so. You'd continue to see the STDERR on the terminal.

In order to redirect both the STDOUT and STDERR of the command into the variable, say:

output=$(liquibase --"lots of parameters here" 2>&1)

In order to redirect the STDOUT into the variable and discard the error completely, say:

output=$(liquibase --"lots of parameters here" 2>/dev/null)
devnull
  • 118,548
  • 33
  • 236
  • 227
  • just a side question, do you think I can redirect stdout into a variable and stderror into another variable, without running the liquibase command twice – kali Nov 22 '13 at 14:56
  • 1
    @kali [This question](http://stackoverflow.com/questions/11027679/bash-store-stdout-and-stderr-in-different-variables) might answer what you want. – devnull Nov 22 '13 at 15:08