Linux - NewbieThis 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!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I have a script which can be called from command line as:
hc -t SW HEALTH -l
The argument for -t option is "SW HEALTH". But when I use getopts and use $OPTARG for getting the argument, I get only SW as the output.
Is there a way I can deal with the space and get the entire option?
Im sorry.. Maybe I was not clear.
I call the script as:
hc -t SW HEALTH -l
As pan64 suggested, you need to quote SW HEALTH:
hc -t "SW HEALTH" -l
I have shown double quotes because they are easier to see. If there's nothing in the string for the shell to substitute and the string does not contain a single quote (as is the case with SW HEALTH) then single quotes would be more appropriate.
Sorry but even "$OPTARG" does not work. it still gives only SW
Is the output of echo "DEBUG: type: >$OPTARG<" "DEBUG: type: >SW<"?
If so and you are using hc -t "SW HEALTH" -l, then you could try
Some older shells required that.
It would be helpful if you could copy and paste from your command prompt session into this thread (ideally within CODE tags) then we could see exactly what you are doing and what the output is. Much more useful than "does not work"!
If someone helps you, or you approve of what's posted, click the "Add to Reputation" button, on the left of the post.
Happy with solution ... mark as SOLVED
(located in the "thread tools")
While its all worked out fine, I don't think the main point was addressed.
Your script can't take account of spaces in a single argument if you don't have control of the input, although if your script only takes one argument, then you could read all the arguments and then concatenate them.
Generally It's easier to throw an error if you get something unexpected.