The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-24-2007
habuzahra habuzahra is offline
Registered User
  
 

Join Date: Oct 2006
Posts: 29
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
  #2 (permalink)  
Old 10-24-2007
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
  
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,628
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
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:37 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0