Find the answer to your Linux question:
Results 1 to 3 of 3
in a shell script if i have a string eg: "how are you" how do i pass it to the c program command line arguments such as argv[0]="how are you"....hhow ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Dec 2007
    Location
    bangalore
    Posts
    38

    command line arg


    in a shell script if i have a string eg: "how are you" how do i pass it to the c program command line arguments such as argv[0]="how are you"....hhow to pass this string and recieve it in one piece in c prog....................plz reply quick

  2. #2
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Quote Originally Posted by robinsonvpanicker View Post
    in a shell script if i have a string eg: "how are you" how do i pass it to the c program command line arguments such as argv[0]="how are you"....hhow to pass this string and recieve it in one piece in c prog....................plz reply quick
    One of the many results with a quick search with Google:

    The GNU C Programming Tutorial

    Regards

  3. #3
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    C's argv[] array is its commandline arguments. So in a script, I would do:
    Code:
    #!/bin/bash
    
    arg=another argument
    
    ./my_program arg1 arg2 arg3 "$arg"
    And the argv[] array for my_program will be:
    Code:
    argv[0] = ./my_program
    argv[1] = arg1
    argv[2] = arg2
    argv[3] = arg3
    argv[4] = another argument

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •