If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Accept input parameters

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-14-04, 01:02
lloydnwo lloydnwo is offline
Registered User
 
Join Date: Aug 2003
Location: India
Posts: 262
Accept input parameters

Dear All,

I got a table creation file in a standard format. I need to accept parameters from the user & then based on the input change the data in the file. For. eg.
i will accept the database name, dbspace name & user name from the user and accordingly change the same in the table creation file. Any ideas???.
Thanks in advance.

Regards,

lloyd
Reply With Quote
  #2 (permalink)  
Old 09-14-04, 02:16
saurav101 saurav101 is offline
Registered User
 
Join Date: Oct 2003
Posts: 19
You can do this in many ways .
1. Pass the arguments on the command line and access values as $1 $2 etc from inside the script .
2. For a more descriptive solution you can use the
<script> -d <dbname> -u <username> and so on and access the values using the getopts command inside the script.
3. You can also store the configurable values in a file and read the file before invoking the table creation script.
Let me know if you need any further help

Thanks
Saurav
Reply With Quote
  #3 (permalink)  
Old 09-14-04, 04:28
lloydnwo lloydnwo is offline
Registered User
 
Join Date: Aug 2003
Location: India
Posts: 262
Hi Saurav,

Thanks for your reply, can you pls. give me an eg. of it. I need to accept these parameters & based on the input reflect the changes in the other file(table creation file). My script would be -
<script> -d <dbname> -u <username> -dbs <dbspace>
can you give an eg of the above. At the prompt user will enter
<script> -d <dbname> -u <username> -dbs <dbspace> and based on the input i will change the table creation script using sed command. Thanks in advance.

Regards,

lloyd
Reply With Quote
  #4 (permalink)  
Old 09-14-04, 07:13
ducasio ducasio is offline
Registered User
 
Join Date: Aug 2004
Location: Rome, Italy
Posts: 81
normally you have to use the one character options, so:
script -d <dbname> -u <user> -c <dbstring>

Inside of the script you must have this first instructions:

while getopts "d:u:c:" opt
case
d)DBNAME=$OPTARG;;
u)USERNAME=$OPTARG;;
c)DBSTRING=$OPTARG;;
])echo "Wrong Option Applied: " $opt; exit 0;;
esac
done
Reply With Quote
  #5 (permalink)  
Old 09-14-04, 08:10
lloydnwo lloydnwo is offline
Registered User
 
Join Date: Aug 2003
Location: India
Posts: 262
Hi ducasio,

thanks for the script.

Regards,

lloyd
Reply With Quote
  #6 (permalink)  
Old 09-15-04, 08:59
ducasio ducasio is offline
Registered User
 
Join Date: Aug 2004
Location: Rome, Italy
Posts: 81
Pleased to be useful
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On