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


 
Thread Tools Search this Thread
Top Forums Programming How to pass the command line arguments to the shell script in c language?
# 1  
Old 05-01-2012
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..???
Smilie
Moderator's Comments:
Mod Comment Please use code tags

Last edited by jim mcnamara; 05-01-2012 at 09:24 AM..
# 2  
Old 05-01-2012
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);

This User Gave Thanks to shamrock For This Post:
# 3  
Old 05-02-2012
hello shamrock,
this has been solved much issue.
Thank you, Smilie
regards,
Sharlin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pass Arguments to Command from Shell Script

Hi all, I am working on a project, in which I have to connect to Bluetooth low energy device. I am able to connect and do data transfer from command line. But I want to do from script Here is my script #!/bin/bash #sudo hcitool -i hci0 lescan sleep 1 sudo hcitool -i hci0 lecc --random... (8 Replies)
Discussion started by: nithin@embdes
8 Replies

2. Shell Programming and Scripting

How to pass command line arguments to awk program?

#!/bin/awk -f BEGIN { FS=":"; } { if ( $7 == "" ) { print $1 ": no password!"; } } I want to execute this program for a particular user to check for his password from the file /etc/passwd (as the input file) and the user details to be given... (1 Reply)
Discussion started by: sri.phani
1 Replies

3. Shell Programming and Scripting

Parsing Command Line Arguments In C shell script

]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)
Discussion started by: codecatcher
11 Replies

4. Shell Programming and Scripting

How to use case and command line arguments in shell script?

Hi... can anyone please help me out in using the CASE and command line argument in shell script... i am bit new to shell scripting...below i have explained my proble with example... say i have an executable file with name 'new1.sh' and there are 3 functions in it a(), b() and c()....and there... (5 Replies)
Discussion started by: swap21783
5 Replies

5. Shell Programming and Scripting

Shell script command line arguments

Hello All, i am known to the limitation of different shells while passing more than 9 command line arguments i just tried the example below i do see my current shell is tcsh echo $SHELL /bin/tcsh so if i make my script executable and run it output is ... (6 Replies)
Discussion started by: Deepak Dutt
6 Replies

6. Shell Programming and Scripting

How can i pass 2 command line arguments with a range between them

Hi, I am writting a script. i am not sure what i am trying to do is possible or not. thats why asking the best of the best. the script i want to write will recieve as input parameters 2 different options. as in MODE 1 -- start_date / end_date (2 dates has 2 go at a time MODE 2... (2 Replies)
Discussion started by: dazdseg
2 Replies

7. UNIX for Dummies Questions & Answers

Bourne Shell Script that only takes command line arguments

Does anybody know how to Accept a “userid” as a command line argument on a Unix Bourne Shell Script? The output should be something like this: User userid has a home directory of /path/directory the default shell for this user is /path/shell (5 Replies)
Discussion started by: ajaira
5 Replies

8. UNIX for Advanced & Expert Users

Bourne Shell Script that only takes command line arguments

Does anybody know how to Accept a “userid” as a command line argument on a Unix Bourne Shell Script? The output should be something like this: User userid has a home directory of /path/directory the default shell for this user is /path/shell (1 Reply)
Discussion started by: ajaira
1 Replies

9. Shell Programming and Scripting

Bourne Shell Script that only takes command line arguments

Does anybody know how to Accept a “userid” as a command line argument on a Unix Bourne Shell Script? The output should be something like this: User userid has a home directory of /path/directory the default shell for this user is /path/shell (1 Reply)
Discussion started by: ajaira
1 Replies

10. Shell Programming and Scripting

Pass command line arguments to awk

I am trying to pass max as a sommand line argument when I call awk. Made the modification in the BEGIN but it is not working I'm getting an error as below: awk: txsrx.awk:82: (FILENAME=jcd.tx FNR=4161) fatal: cannot open file `40' for reading (No such file or directory) Somehow it... (2 Replies)
Discussion started by: kristinu
2 Replies
Login or Register to Ask a Question