joshualan
joshualan

Reputation: 2140

In a Linux script, is it possible to execute multiple commands in the same process?

I have a script that contains:

db2 connect to user01
db2 describe indexes for table table_desc

What I figure is happening is the process that executes the first line is different from the process that runs the second line. This means that the process that executes the first line gets the connection while the second process that runs the second line has no connection at all. This is verified because I get an error at the second line saying that there exists no database connection.

Is it possible to have the same process run both commands? Or at least a way to "join" the first process to the second?

Upvotes: 3

Views: 912

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200293

If you want both instructions to run in the same process you need to write them to a script:

$ cat foo.db2
connect to user01
describe indexes for table table_desc

and run that script in the db2 interpreter:

db2 -f foo.db2

A Here Document might work as well:

db2 <<EOF
connect to user01
describe indexes for table table_desc
EOF

I can't test that, though, since I currently don't have a DB2 on Linux at hand.

Upvotes: 7

Related Questions