I am writing the following script:
#!/bin/bash
db2 connect to andres
a=$(db2 connect)
echo $a
b=$(db2 connect && echo $?)
echo $b
c=$(db2 connect ; echo $?)
echo $c
d=$(db2 connect)
echo $d
What I am doing is to execute multiples commands inside a subshell by using the current established connection; however, the connection is only identified as connected when only a db2 command is issued. If I use a pipe or multiple commands in the subshell, the connection is not identified. Why?
$ ./test
Database Connection Information
Database server = DB2/LINUXX8664 10.5.5
SQL authorization ID = DB2INST1
Local database alias = ANDRES
Database Connection Information Database server = DB2/LINUXX8664 10.5.5 SQL authorization ID = DB2INST1 Local database alias = ANDRES
SQL1024N A database connection does not exist. SQLSTATE=08003
SQL1024N A database connection does not exist. SQLSTATE=08003 4
Database Connection Information Database server = DB2/LINUXX8664 10.5.5 SQL authorization ID = DB2INST1 Local database alias = ANDRES
As you can see, the connection is still active after the last statement.