My earlier post wasn't what you wanted.. I don't think I understood your question at first.
Quote:
Originally posted by jayakhanna I wan' t a system call and need not want to tokenize either, I just want to execute the way as normal program does.
A "normal" program executes the way cbkihong suggested. For example, if you use the find command to find a file called "some file" with a space in it, then you have to surround the name of that file with quotes or the command will fail. From the timestamp on the posts, I can see you most likely didn't see cbkihong's post before you posted...
suppose I am using getopt function, in a C program and try to caputre the arguments with the -x option then how can I do that.
Like I have a command ls abc def, this is just an example now I want to wrap it up in some other function. So basically i write this
now here comes the problem how will I copy optarg to buf, because \0 will be there at the end of the first string so only the first string will be stored in buf
I tried to do this
and then print dest[i ] its showing that optarg has all the arguments whatever we pass with -x, now how to determine how many arguments are passed with -x,
Here I am giving the i value randomly, how will I determine the exact i value.
Now this arguments needs to be passed to ls which i will call in some other part like system ("ls arguments) got from above which will stored in some variable
Hoping that you understood the real problem
Regards
JK
[i]added code tags and spaces to so rest of post wasn't italicized --oombera
Yes, I understand your problem. I don't know if any Unix variants have special extensions. Otherwise, from my interpretation of the getopt manpage I believe getopt doesn't expect multiple parameters to a single option, at all.
So, for example, if you invoke this as
./a.out -x abc def -a
Then argv[] is an array consisting of
-x
abc
def
-a
(not showing argv[0] above)
What getopt does is that it monotonically scans forward. It identifies '-x', associates 'abc' as optarg. It doesn't know what 'def' is, and throw it to the end. Then it identifies '-a', and so on. 'def' is left at the end and regarded as a non-option (the index of which you get with optind). Therefore, as getopt proceeds it permutes the order of arguments that appear in argv[].
I made this test program to illustrate the idea:
./a.out -x abc def -a
gives
I think conventional Unix tradition is that there is at most one argument for each option. I think this is because getopt allows options to be given in any order. So if you would like to break this convention you can always write your own routine to parse argv[]. Of course that will not be easy if your program has to accommodate a variety of options. Formally speaking, that requires parser construction knowledge (lexical analysis) that are beyond the scope of this forum.
]I have a string like "/abc/cmind/def/pq/IC.2.4.6_main.64b/lnx86" and this string is given by user. But in this string instead of 64b user may passed 32 b an i need to parse this string and check wether its is 32b or 64 b and according to it i want to set appropriate flags.
How will i do this... (11 Replies)
Hi,
I've a python script called aaa.py and passing an command line option " -a" to the script like, ./aaa.py -a
& Inside the script if the -a option is given I do some operation if not something else.
code looks like
./aaa.py -a
.
.
if options.a
---some operation---
if not options.a... (1 Reply)
hi,,,,
I want to create a command prompt, for example "prompt>", so my prompt need to handle commands, for example "prompt>cmd", so i want to know how to get arguments for my own commands cmd, i.e. default argc should contain arguments count and argv should point to the argument vector i.e, for... (2 Replies)
hi, can someone how to accept command line arguments as a variable using in script?
like: ./scriptname arguments
by accept arguments, I can use it in my script?
thx! (1 Reply)
Hi,
Can anyone please help me to know what is the maximum number of command line arguments that we can pass in unix shell script?
Thanks in advance,
Punitha.S (2 Replies)
Looking for a little help parsing some command line arguments in a bash script I am working on, this is probably fairly basic to most, but I do not have much experience with it.
At the command line, when the script is run, I need to make sure the argument passed is a file, it exists in the... (3 Replies)
I am working on a script wherein i need the user to enter the Build ID
for eg:the command line will show
enter the build ID
Now on entering the build ID it should be assigned to @ARGV.
How can this be done.? (1 Reply)
--------------------------------------------------------------------------------
I have this while loop and at the end I am trying to get it to tell me the last argument I entered. And with it like this all I get is the sentence with no value for $1. Now I tried moving done after the sentence... (1 Reply)
Hi all,
How many arguments can we pass while testing a prgm at command line..
I encountered an issue while passing 10 arguments.
For $10 its taking argument passed for $1 followed by 'zero'.
can we pass more than 9 arguments /Is there any other way.
Thanks,
rrs (6 Replies)
Hi
How to pass multi line text as a command line argument to a program.
(i.e)
./a.out hi this is sample 0 file1
where
hi this is sample should be stored in argv
0 in argv and so on... (3 Replies)