How to Pass variable to shell Script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to Pass variable to shell Script
# 1  
Old 08-22-2005
How to Pass variable to shell Script

Hi ,

i am beginner to Unix, I have one small script which execute java programme,it has java command input output structure . Right now i have given Input output structure manually that is on same directory, now how can i pass that by commandline

#!/bin/sh

java Classjava input.txt output.xml output.structure


How can i pass variable parameter from command line.

Thanks

sam70
# 2  
Old 08-22-2005
#!/bin/sh

java Classjava $1 output.xml output.structure

Now that $1 will be replaced by the first command line argument. You can use $2, $3, etc as well.
# 3  
Old 08-23-2005
Regarding passing variable

Hi ,

I have tried putting $1 $2 but it doesnt work

Thanks

sam70
# 4  
Old 08-23-2005
Can you copy and paste the results?
# 5  
Old 08-23-2005
Regarding Variable parameter to be passed

Hi ,

Here is message

Usage: TFFtoXML <output.xml> <input.flat> <input.ffd> [logfile]


this is java command to be executed on shell script. this output we see when
we execute this on command line in local machine.it is a .bat file and we do
ff2xml and enter then it gives this information as above which i see when i put $1 $2 . But it not asking for variable input.

THanks

sam70
# 6  
Old 08-23-2005
It won't ask for variable input. It will behave the way you requested in your first post. Remember this? "How can i pass variable parameter from command line."

That script is in a file. The file has a name. Somehow you invoke the script by name. Let's say that you named the script "fred". You might use:
fred
./fred
/some/path/to/fred
when you run it. That is the command line. Put a space after fred. Type another word. That word will be $1 inside the script.
./fred input.txt
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to pass the config file lines as variable on the respective called function on a script

I want to make a config file which contain all the paths. i want to read the config file line by line and pass as an argument on my below function. Replace all the path with reading config path line by line and pass in respective functions. how can i achieve that? Kindly guide. ... (6 Replies)
Discussion started by: sadique.manzar
6 Replies

2. Shell Programming and Scripting

How to pass variable from awk script to shell?

Hi, Please need to print the Rej variable outsite the awk script which is given below...please advised how to achieve it. #!/bin/bash echo "Enter DMU Pipe delimited File name for the Feed to be validated" read DMU_File echo "Enter Pre-DMU File name for the Feed" read Predum_file ... (3 Replies)
Discussion started by: pelethangjam
3 Replies

3. Shell Programming and Scripting

Unable to pass shell script variable to awk command in same shell script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist. diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk... (2 Replies)
Discussion started by: Ashunayak
2 Replies

4. Shell Programming and Scripting

How to pass Variable from shell script to select query for SqlPlus?

echo "set echo off"; echo "set feedback off"; echo "set linesize 4000"; echo " set pagesize 0"; echo " set sqlprompt ''"; echo " set trimspool on"; Select statement is mentioned below echo "select res.ti_book_no from disney_ticket_history res where res.ti_status =${STATUS} and... (7 Replies)
Discussion started by: aroragaurav.84
7 Replies

5. Shell Programming and Scripting

How to pass nawk variable to shell within the same script?

Hi All, I tried googling but so far no luck, can someone tell me how pass the variable value used inside the nawk command to shell. In the below script i get the value of $c (without color: Total Executed: " c ") but the printf which is outside the nawk command doesn't print the value or it... (4 Replies)
Discussion started by: Optimus81
4 Replies

6. Shell Programming and Scripting

How to pass a variable as a parameter to DB2 database from shell script

I need to pass a variable as a parameter from shell script into a DB2 database. var=bhuk_1123_Q_11/22/09 select * from tbl1 where serial_id='$var'; I have tried executing it using db2 -tvf scriptname Somebody please help me out with this. It is throwing an error. Please tell me how... (2 Replies)
Discussion started by: ss3944
2 Replies

7. Shell Programming and Scripting

pass variable from awk to shell script

Hello Experts, Actually I was searching for a solution here in this forum , but didn't get what exactly I want . Is this possible to do in awk ? I am trying to do some thing like below in ksh script . Upto my knowledge I can pass shell script to awk with "-v " option. But I... (3 Replies)
Discussion started by: user_prady
3 Replies

8. Shell Programming and Scripting

Is it possible to pass variable from awk to shell script

Hello experts, can I return a value from gawk to a shell script ? My script as follows, #Here I want the num value to shell script so that I can use later gawk ' { split($0,num,","); print num }' gawk -v no=$number '{print no}' file1 ... (3 Replies)
Discussion started by: user_prady
3 Replies

9. UNIX for Dummies Questions & Answers

How to pass Shell script variable to awk

Hi, I have a shell script with an ambedded awk script. i need to pass a script variable to the awk script. Please help. Thanks in advance Himani (3 Replies)
Discussion started by: HIMANI
3 Replies

10. UNIX for Dummies Questions & Answers

How to pass a oracle variable back to the shell script

Hi, I am calling an oracle function that returns a number (either 0 or 2), how do I pass that pass to the wrapping shell script as I would like to do other things based on the value returned by the oracle function. Your help will be appreciated. -------------------------- sqlplus / <<... (3 Replies)
Discussion started by: Jtrinh
3 Replies
Login or Register to Ask a Question