how to pass command-line parameter to shell script?
Hello,
I am new to linux and very new to shell scripting. How does one pass a command-line parameter to a shell script? In DOS/OS/2 terms, I am looking for the equivalent of %1 etc. Thanks. |
"How does one pass a command-line parameter to a shell script?"
The command line parameters are referenced as $1, $2, etc. -------------------------------- Steve Stites |
$0 is the name of the command
$1 first parameter $2 second parameter $3 third parameter etc. etc $# total number of parameters $@ all the parameters will be listed but in all honesy, you can go to shelldorado.com and get everything you want to know on sh, ksh, csh, bash, javascript etc. Great site with tutorials, examples, everything you will need. |
Passing arguments to a shell script
Here is an article, How to pass arguments to a shell script
http://bashscript.blogspot.com/2009/...ll-script.html I hope this will clear most of your doubts |
|
Shell named parameter passing
Is there a way to pass named parameters to shell script
like Code:
$] ./shell PASS=123 NAME='KKK' Code:
echo $PASS |
Yes, read the messages above which explain how to do this.
|
Quote:
Code:
PASS=123 NAME=KKK shell.sh |
That's great -- a 7 year old thread gets a new post and OP Kropotkin replies the same minute! :eek:
|
i want it like this
shell.sh file Code:
Quote:
Quote:
|
Sugar, I didn't notice that:)
xombboxer: I provided you with the solution. By the way, in the future don't highjack other people's threads (especially 3-year old ones). Create your own thread instead. |
@sycamorex
i was in dilemma whether to start a new thread or search for the similar one already exists.... so i came here and contunued... :( ok Back to my question.. you said Quote:
can you explain me bit ( newbie :( ) how to pass the parameter and how to handle it inside the script file thanks |
Given that your shell.sh script looks like you posted above, you can execute it (ans pass the values to the variables) by typing what I suggested. The values will be passed to the script and echo will display the passed values. Is that what you wanted?
|
All times are GMT -5. The time now is 08:43 AM. |