Pass command line arg to sql file

Hi all,
How to pass the command line argument to a sql file

Script:

#!/bin/ksh
 
if  [[ ${2} = -n && ${#} = 3 ]] ; then
 
test.sql                          
 
fi

My Sql Informix DB:
echo "select * from table where col1 = 2234
and col2 = '$3'"|dbaccess ddname

But im getting `:' unexpected error

you have "$3" surrounded by single quotes which means the shell will not evaluate it ...

Try this:

test.sql $3

and

select * from table where col1 = 2234
and col2 = '&1'

Thanks, how to pass variable to sql file.
Im tryin in two ways,

Method 1:
my.sql

select * from table where col1 = '$1' and col2 = 'text'; 
 
Method 1execute: dbaccess database my.sql $var 

Method2:

select * from table col1 in (`cat inputfile`) and col2 = 'text';
 
method 2execute: dbaccess database my.sql 
 

But both throwing error.

I dont know about the db connection and execution of sql commands, but it seems that you are passing the my.sql itself as a parameter file to the dbaccess command.

HERE and echo example to expand value of variable using some kind of "template":

x=111
# here
cat <<EOF
select * from table where col1 = '$x' and col2 = 'text';
EOF

# normal command line expansion. ' ' are inside " " = only characters without special meanings
echo "delete from table where col1 = '$x' and col2 = 'text';"

I'm not used dbaccess cmd, but something like:

x=111

dbaccess args <<EOF
select * from table where col1 = '$x' and col2 = 'text';
EOF

dbaccess args <<EOF > output.result.file
select * from table where col1 = '$x' and col2 = 'text';
EOF
#or
echo "delete from table where col1 = '$x' and col2 = 'text'  ;  " | dbaccess args  > output.result.file

dbaccess <<EOF
select * from table col1 in (  $(cat inputfile)  ) and col2 = 'text';
EOF