LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Passing arguments to shell script like perl script get-opts (https://www.linuxquestions.org/questions/linux-newbie-8/passing-arguments-to-shell-script-like-perl-script-get-opts-848074/)

somupl86 12-02-2010 11:02 PM

Passing arguments to shell script like perl script get-opts
 
Hi,

I was trying to pass arguments to shell script in such a way that perl script get-opts behaves.

Example:
Present Shell:

sh shell.sh arg1 arg2 arg3

perl perl.pl --arg2=2 --arg1=1 --arg3=3

I think you got my point

In shell script we need to give them in order with out knowing the significance of the argument, where as in perl we can give in any order by some identification.

This is what i need the same is in shell script.

Please help.

chrism01 12-02-2010 11:13 PM

Use the getopts cmd
http://tldp.org/LDP/abs/html/internal.html#EX33
http://tldp.org/LDP/abs/html/internal.html
http://bashcurescancer.com/the-60-se...-tutorial.html

catkin 12-02-2010 11:14 PM

The shell builtin command getopts does what you want. There's a tutorial on the Bash Hackers Wiki.


All times are GMT -5. The time now is 02:14 PM.