Search the web
Sign In
New User? Sign Up
linux-bangalore-programming · LB Programming Discussions
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
command line argument + '*'   Message List  
Reply | Forward Message #7559 of 7584 |
Re: [blug-prog] command line argument + '*'

bash is interpreting * and passing it as the list of files in the
current directory, you could try passing escape sequence with * and
see what is the behavior.
-sujay

On Wed, Jun 10, 2009 at 8:02 PM, prabhjot
singh<prabhjotsinghengineer@...> wrote:
>
>
> Hi,
>
> I write a very simple program to print command line arguments.
> As and when program hits '*' in received arguments It converts it to list of
> files in current directory.
>
> My questions/doubts:
> 1) What is the reason behind this?
> 2) Can't I pass * as command line argument?
>
> #include <stdio.h>
> int main(int argc, char *argv[])
> {
> int i = 0;
> printf("argc: [%d]", argc);
> while (i < 10 && i < argc)
> printf("%s\n", argv[i++]);
> }
> output:-
>
>>./a.out *
> argc: [38]
> /*here goes list of files*/
>
> --
> Platform used: RH Linux - Bash shell | compiler: gcc [egcs-2.91.66 ]
>
> --
> Thanks
> PS
>
> [Non-text portions of this message have been removed]
>
>



Thu Jun 11, 2009 4:48 am

sg10b_2000
Offline Offline
Send Email Send Email

Forward
Message #7559 of 7584 |
Expand Messages Author Sort by Date

Hi, I write a very simple program to print command line arguments. As and when program hits '*' in received arguments It converts it to list of files in...
prabhjot singh
cepsingh
Offline Send Email
Jun 10, 2009
3:58 pm

... The * was converted to a list of files by the shell you use eg:bash. Try "./a.out \*" and you should get * as an argument. Any special character ...
Burbure, Pavan (GE He...
pavanburbure
Offline Send Email
Jun 11, 2009
4:55 am

... * on command line is expanded by shell to list of files. Thus when you run program the actual arguments to program are list of files in working directory. ...
Balwinder Singh
BALWINDER@...
Send Email
Jun 11, 2009
6:22 pm

... Yes...you can. Pass the argument as string. Example... >a.out '*' . This is because the asterisk without quote has a special meaning for shell. You can...
Nirmalya Lahiri
nirmalyalahiri
Offline Send Email
Jun 11, 2009
6:22 pm

Hi prabhjot, try ./a.out \* Use escape sequence \ to send a * Thanks, Ganaraj ________________________________ From: prabhjot singh...
Ganaraja Ng
ganaraja_linux
Offline Send Email
Jun 11, 2009
6:22 pm

Hi, * is one of the metacharacter(special character) in unix shell. * - matchess zero or more characters . for eg: foo* - matches all files that start with...
vinod
vin_vrs
Offline Send Email
Jun 11, 2009
6:23 pm

bash is interpreting * and passing it as the list of files in the current directory, you could try passing escape sequence with * and see what is the behavior....
sujay g
sg10b_2000
Offline Send Email
Jun 11, 2009
6:23 pm

Thanks to all! Your suggestion works reply helped. -- Prabhjot ... [Non-text portions of this message have been removed]...
prabhjot singh
cepsingh
Offline Send Email
Jun 12, 2009
8:09 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help