Unix/Linux Go Back    


Programming Post questions about C, C++, Java, SQL, and other programming languages here.

How to pass the command line arguments to the shell script in c language?

Programming


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 05-01-2012
sharlin sharlin is offline
Registered User
 
Join Date: May 2012
Last Activity: 25 June 2013, 4:43 AM EDT
Posts: 5
Thanks: 3
Thanked 0 Times in 0 Posts
How to pass the command line arguments to the shell script in c language?

hi,
I am new in the shell script, and c programming with linux. I am looking to pass the arguments in c program that should be executed by the shell script.
Code:
e.g.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{       int i;
        for (i=1;i<argc; i++)
        {
                return system("/bin/migrate argv[i]"); <--- keep attention here
        }
        return 0;
}

here the migrate is shell script taking agrument as "argv[i]" but not actual argument passed to the program.
can anybody help me for this..???
Linux
Moderator's Comments:
Please use code tags

Last edited by jim mcnamara; 05-01-2012 at 08:24 AM..
Sponsored Links
    #2  
Old Unix and Linux 05-01-2012
shamrock shamrock is offline Forum Advisor  
Registered User
 
Join Date: Oct 2007
Last Activity: 15 April 2015, 10:26 AM EDT
Location: USA
Posts: 1,556
Thanks: 25
Thanked 150 Times in 142 Posts
First you need to concatenate the arguments to the system command before you pass it on to it for execution...

Code:
char command[100];
sprintf(command, "%s %s", "/bin/migrate", argv[1]);
system(command);

The Following User Says Thank You to shamrock For This Useful Post:
sharlin (05-02-2012)
Sponsored Links
    #3  
Old Unix and Linux 05-02-2012
sharlin sharlin is offline
Registered User
 
Join Date: May 2012
Last Activity: 25 June 2013, 4:43 AM EDT
Posts: 5
Thanks: 3
Thanked 0 Times in 0 Posts
hello shamrock,
this has been solved much issue.
Thank you, Linux
regards,
Sharlin
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to use case and command line arguments in shell script? swap21783 Shell Programming and Scripting 5 03-23-2011 02:29 PM
Shell script command line arguments Deepak Dutt Shell Programming and Scripting 6 12-20-2010 06:36 AM
How can i pass 2 command line arguments with a range between them dazdseg Shell Programming and Scripting 2 05-28-2010 08:17 AM
Bourne Shell Script that only takes command line arguments ajaira UNIX for Dummies Questions & Answers 5 03-25-2010 04:59 PM
Pass command line arguments to awk kristinu Shell Programming and Scripting 2 12-15-2009 10:31 AM



All times are GMT -4. The time now is 10:09 AM.