![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| ssh - passing password in shell script | Muktesh | Shell Programming and Scripting | 5 | 05-05-2009 12:37 PM |
| passing two variables into a shell script? | Bashar | Shell Programming and Scripting | 2 | 05-15-2007 10:00 AM |
| Passing Values from a shell script | dhananjaysk | Shell Programming and Scripting | 6 | 04-06-2006 09:33 AM |
| Passing value from shell script to .pls file | dreams5617 | Shell Programming and Scripting | 4 | 11-30-2004 07:16 PM |
| passing awk variable to the shell script | bcheaib | Shell Programming and Scripting | 3 | 07-21-2004 10:00 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Passing argumnets from shell script to sql
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: Code:
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
bakunin |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|