LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-02-2010, 11:02 PM   #1
somupl86
LQ Newbie
 
Registered: Nov 2010
Posts: 13

Rep: Reputation: 0
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.
 
Old 12-02-2010, 11:13 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,295

Rep: Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358
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
 
Old 12-02-2010, 11:14 PM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] passing commands as arguments to functions in bash script mastahyeti Linux - General 3 05-31-2010 06:19 PM
Calling perl script and passing variable from php script hosea Programming 5 10-21-2008 08:01 AM
Passing arguments to a shell script subu_s Programming 3 09-02-2005 05:13 AM
Apache passing arguments to a shell script disabled? mikeyt_333 Linux - Security 3 08-03-2004 06:09 PM
Issue with recursive script passing arguments gauge73 Linux - Newbie 0 01-06-2004 07:16 PM


All times are GMT -5. The time now is 12:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration