Sponsored Content
Top Forums Programming How to pass the command line arguments to the shell script in c language? Post 302632913 by sharlin on Tuesday 1st of May 2012 06:15:01 AM
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..
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
exit(1) 							   User Commands							   exit(1)

NAME
exit, return, goto - shell built-in functions to enable the execution of the shell to advance beyond its sequence of steps SYNOPSIS
sh exit [n] return [n] csh exit [ ( expr )] goto label ksh *exit [n] *return [n] DESCRIPTION
sh exit will cause the calling shell or shell script to exit with the exit status specified by n. If n is omitted the exit status is that of the last command executed (an EOF will also cause the shell to exit.) return causes a function to exit with the return value specified by n. If n is omitted, the return status is that of the last command exe- cuted. csh exit will cause the calling shell or shell script to exit, either with the value of the status variable or with the value specified by the expression expr. The goto built-in uses a specified label as a search string amongst commands. The shell rewinds its input as much as possible and searches for a line of the form label: possibly preceded by space or tab characters. Execution continues after the indicated line. It is an error to jump to a label that occurs between a while or for built-in command and its corresponding end. ksh exit will cause the calling shell or shell script to exit with the exit status specified by n. The value will be the least significant 8 bits of the specified status. If n is omitted then the exit status is that of the last command executed. When exit occurs when executing a trap, the last command refers to the command that executed before the trap was invoked. An end-of-file will also cause the shell to exit except for a shell which has the ignoreeof option (See set below) turned on. return causes a shell function or '.' script to return to the invoking script with the return status specified by n. The value will be the least significant 8 bits of the specified status. If n is omitted then the return status is that of the last command executed. If return is invoked while not in a function or a '.' script, then it is the same as an exit. On this man page, ksh(1) commands that are preceded by one or two * (asterisks) are treated specially in the following ways: 1. Variable assignment lists preceding the command remain in effect when the command completes. 2. I/O redirections are processed after variable assignments. 3. Errors cause a script that contains them to abort. 4. Words, following a command preceded by ** that are in the format of a variable assignment, are expanded with the same rules as a vari- able assignment. This means that tilde substitution is performed after the = sign and word splitting and file name generation are not performed. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
break(1), csh(1), ksh(1), sh(1), attributes(5) SunOS 5.10 15 Apr 1994 exit(1)
All times are GMT -4. The time now is 05:21 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy