473,399 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

giving options in shell scripts

sumittyagi
202 Expert 100+
Hi All!
could you please guide me how to add an option to a shell script, and how to extract that option in the script.

For eg. if we give arguments to a script, then we get that argument by numbered variables in the script.
abc.sh xyz

here we will get the argument in the shell like:
firstArg=$1

But if I want to give an option with my script like:
abc.sh -d xyz

then how will I get that option, and will there be any change in the way I extract my argument.

like:
firstArg=($2 instead of $1)

and could option be captured in positional variables.
like:
opt=$1

Please guide me in this context.

Thanks a lot!
Jan 7 '08 #1
2 2243
numberwhun
3,509 Expert Mod 2GB
Hi All!
could you please guide me how to add an option to a shell script, and how to extract that option in the script.

For eg. if we give arguments to a script, then we get that argument by numbered variables in the script.
abc.sh xyz

here we will get the argument in the shell like:
firstArg=$1

But if I want to give an option with my script like:
abc.sh -d xyz

then how will I get that option, and will there be any change in the way I extract my argument.

like:
firstArg=($2 instead of $1)

and could option be captured in positional variables.
like:
opt=$1

Please guide me in this context.

Thanks a lot!
To begin with, we would really need to know what shell you are working with as there are more than one.

I think that this and this may help you though.

Regards,

Jeff
Jan 7 '08 #2
sumittyagi
202 Expert 100+
To begin with, we would really need to know what shell you are working with as there are more than one.

I think that this and this may help you though.

Regards,

Jeff
Thanks numberwhun, the links you provided are really good.
Jan 10 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: eichin | last post by:
One of my recent projects has involved taking an accretion of sh and perl scripts and "doing them right" - making them modular, improving the error reporting, making it easier to add even more...
7
by: Robin Becker | last post by:
I wonder if this is the right way to write a medusa(asyncore) server with the win32all framework. Other example services seem to create an event to pass the stop signal from SvcStop into a separate...
9
by: Jeff Wagner | last post by:
I have a project of converting numerous DOS cmd shell scripts to Python. Is there a tutorial to getting started? Thanks, Jeff
3
by: Sara Khalatbari | last post by:
There are a lot of commands that I need to use in my code & I don't know how to do it Is there a way to use shell commands in Python code? __________________________________ Do you...
21
by: godwin | last post by:
Hi all, I wanna thank Martin for helping out with my ignorance concerning execution of stored procedure with python. Now i have decided to write a web app that googles into my companies...
8
by: 4.spam | last post by:
Hello. WinXP, db2 v8.2.7 When I use UPDATE COMMAND OPTION USING <any_switchON(or OFF) it seems that this command has absolutely no effect on these switches since command LIST COMMAND...
3
by: Rocky Zhou | last post by:
I wonder is there any way to make the wrapper program can wrap options && arguments for the the subprocess/command the wrapper will execute? by getopt or optparse module? This is something...
1
by: creeds | last post by:
Hello , I am thinking of performing databse operation using shell scripts , for example i am in need to delete sum number from database very often so if i just run a shell scripts and give that...
7
by: Samuel A. Falvo II | last post by:
I have a shell script script.sh that launches a Java process in the background using the &-operator, like so: #!/bin/bash java ... arguments here ... & In my Python code, I want to invoke...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.