hi I all ,
I have sql statment in my shell script , I pass two argument to the script I need to pass the this two arguments to the sql statment
example :
runsql.sh "1" "2"
sql :
updat tables_x set y=0
where
A=:x should subsituted by "1"
and
B=:y shuold subsituted bt "2"
how I can do that
thanks
Your commandline arguments show up in the script as "$1", "$2", etc. If you have more than 9 arguments ($1..$9) you must use "shift" to get all of them.
There is also a special variable "$#", which holds the number of passed arguments and "$*" which holds all passed arguments.
shift will make $9 to $8, ..., $2 to $1 and lose the previous content of $1. $9 which is freed this way will hold the 10th passed argument if there is one.
Here is a little demonstration script to show you the mechanism:
call the following script with different numbers of arguments:
script.sh a b c d
script.sh "a b" c d e f g h
etc.
#! /bin/ksh
typeset chArg1="" # a normal variable
print - "The number of commandline arguments was: $#"
print - "all arguments: $*"
chArg1="$1" # store the first argument in chArg1
print - "you can transfer the arguments to normal variables:"
print - "the first argument directly: $1"
print - "and here the content of chArg1: $chArg1"
print - "we now see the shift-command in action"
while [ $# -gt 0 ] ; do
print - "Next argument..: $1"
print - "all arguments...: $*"
print - "Nr of arguments.: $#"
print - "------------"
shift
done
exit 0
With these mechanisms you should be able to not only put your arguments into your SQL-Statements, but also validate your script to recognize too few/too many or syntaktically wrong arguments.
bakunin