Executing SQL from command line?
Executing SQL from command line?
(OP)
I'm trying to figure out if/how I can execute sql to an informix DB from the command line. I know I can dbaccess dbname filename, but I don't want to have a file...I just want to specify the sql to execute right there from the command line so there's no file to keep up with. Any ideas?
RE: Executing SQL from command line?
The informix dbaccess and isql utilities were written as pipes, so if you don't want to use files you can use "here" documents:
dbaccess -e testdb <<EDS
select * from test_table
<<EDS
or
echo "select * from test_table"|dbaccess -e testdb
of you can even take advantage of shell variables:
export DBNAME=testdb
echo "select * from test_table"|dbaccess -e "$DBNAME"
Also, you might put dbaccess in it's own shell script. Call the script x.ss:
dbaccess -e testdb <<EDS
$1
EDs
and call it this way:
x.ss "select * from test_table"
Regards,
Ed
Schaefer