Sponsored Content
Top Forums Programming how to execute multi command??? Post 302096145 by !_30 on Tuesday 14th of November 2006 06:52:21 AM
Old 11-14-2006
aliG4 , what do you really want dude ?

Code:
int main (int argc, char *argv[])

-this are the parameter's of the main function ( here is a function , which return an integer value ).

argc : is the number of argument's passed , beginning with 0.

*argv[0] , *argv[1] .. : the argument's ?

Whtat does this mean ?

Let's say : ./do bla bla

./do is the 0 argument , bla is the first and second bla is the second.

So if you want to have a program do per example . You may want to execute multiple commands , and pass them like argument's.

Let's say , you want do to execute ps comand you may just enter :

Code:
 ./do ps

- if you want do to execute let's say ping command , you can do :

Code:
 ./do ping

suposing , that you have configured in the program ( your C aplication ) to execute argv[1] as a command.

let's say something like system("argv[1]") .. or something like that ?

This is what do you want ? Smilie
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Plz Help : How to use write command to execute command on some other terminal

Hi Group , I m trying to execute commands on some other system using write command but inspite of executing the commands they r passed as simple messages. - i m writing >write user-id ! ls o ctrl-d inspite of executing the command ls,other terminal shows ! ls. Thnx in advance. (2 Replies)
Discussion started by: Aashish
2 Replies

2. Shell Programming and Scripting

How to build a command into a string rather than execute the command

I'm trying to populate a command line into a variable. It appears to be executing, instead. Here's an example: mycmd='' if ...; then $mycmd='sudo ' fi $mycmd=$mycmd 'sed -i prev s/aaa/bbb/' $myfile res=`$mycmd` (I'm also not sure of the best way to execute the command from the... (1 Reply)
Discussion started by: littlejon
1 Replies

3. Shell Programming and Scripting

Multi Line 'While Read' command issue when using sh -c

Hi, I'm trying to run the following command using sh -c ie sh -c "while read EachLine do rm -f $EachLine ; done < file_list.lst;" It doesn't seem to do anything. When I run this at the command line, it does remove the files contained in the list so i know the command works ie... (4 Replies)
Discussion started by: chrispward
4 Replies

4. Shell Programming and Scripting

Multi thread awk command for faster performance

Hi, I have a script below for extracting xml from a file. for i in *.txt do echo $i awk '/<.*/ , /.*<\/.*>/' "$i" | tr -d '\n' echo -ne '\n' done . I read about using multi threading to speed up the script. I do not know much about it but read it on this forum. Is it a... (21 Replies)
Discussion started by: chetan.c
21 Replies

5. Shell Programming and Scripting

When i am trying to execute export command within a shell script it is saying command not found.

I am running the export command within a view to use that value inside my build script. But while executing it it is saying "export command not found" My code is as follows: -------------------------- #!/bin/sh user="test" DIR="/bldtmp/"$user VIEW="test.view1" echo "TMPDIR before export... (4 Replies)
Discussion started by: dchoudhury
4 Replies

6. Shell Programming and Scripting

How to substract selective values in multi row, multi column file (using awk or sed?)

Hi, I have a problem where I need to make this input: nameRow1a,text1a,text2a,floatValue1a,FloatValue2a,...,floatValue140a nameRow1b,text1b,text2b,floatValue1b,FloatValue2b,...,floatValue140b look like this output: nameRow1a,text1b,text2a,(floatValue1a - floatValue1b),(floatValue2a -... (4 Replies)
Discussion started by: nricardo
4 Replies

7. AIX

How to use dsadm command to run command on multi lpars?

how to run a command, such as "ls -l core" from one lpar to check multi lpars if core file exist? or what way can do a command on all lpars from one lpar? Thanks (1 Reply)
Discussion started by: rainbow_bean
1 Replies

8. Shell Programming and Scripting

How to execute a command on each line of output from another command?

Hello :) new to bash not to programming. I have an on-going need to change the owning group on sets of files and directories from the one they were created with or changed to on update to the one they need to have going forward. find {target_root} -group wrong_group gets me a newline... (4 Replies)
Discussion started by: naftali
4 Replies

9. Shell Programming and Scripting

Execute ssh command with additional terminal command to any remote user not working script

Hello i am having an issue with bash script and this is the code now=$(cat hosts1.txt | awk '{print $2;}') while read n ;do ssh root@$now 'useradd test1; echo -e "test1\ntest1" | passwd test1 && echo "test1 ALL=(ALL:ALL) ALL" >> /etc/sudoers' When i execute only part with cat, it... (8 Replies)
Discussion started by: tomislav91
8 Replies

10. UNIX for Beginners Questions & Answers

Search a multi-line shell command output and execute logic based on result

The following is a multi-line shell command example: $cargo build Compiling prawn v0.1.0 (/Users/ag/rust/prawn) error: failed to resolve: could not find `setup_panix` in `human_panic` --> src/main.rs:14:22 | 14 | human_panic::setup_panix!(); | ... (2 Replies)
Discussion started by: yogi
2 Replies
ARG(2)								System Calls Manual							    ARG(2)

NAME
ARGBEGIN, ARGEND, ARGC, ARGF, arginit, argopt - process option letters from argv SYNOPSIS
#include <u.h> #include <libc.h> ARGBEGIN { char *ARGF(); Rune ARGC(); } ARGEND extern char *argv0; /* Alef only */ Arg *arginit(int argc, byte **argv); Rune argopt(Arg *arg); byte *argf(Arg *arg); DESCRIPTION
These macros assume the names argc and argv are in scope; see exec(2). ARGBEGIN and ARGEND surround code for processing program options. The code should be the cases of a C switch on option characters; it is executed once for each option character. Options end after an argu- ment --, before an argument -, or before an argument that doesn't begin with -. ARGC() returns the current option character. ARGF() returns the current option argument: a pointer to the rest of the option string if not empty, or the next argument in argv if any, or 0. ARGF must be called just once for each option that takes an argument. After ARGBEGIN, argv0 is a copy of argv[0] (conventionally the name of the program). After ARGEND, argv points at a zero-terminated list of the remaining argc arguments. Alef The Alef argument processing routines are unrelated. Instead, an aggr called Arg is initialized by a call to arginit. Successive calls to argopt return successive option characters, or zero at the end of the options. After a call to argopt, argf will return any argument string associated with the option. EXAMPLES
This C program can take option b and option f, which requires an argument. #include <u.h> #include <libc.h> void main(int argc, char *argv[]) { char *f; print("%s", argv[0]); ARGBEGIN { case 'b': print(" -b"); break; case 'f': print(" -f(%s)", (f=ARGF())? f: "no arg"); break; default: print(" badflag('%c')", ARGC()); } ARGEND print(" %d args:", argc); while(*argv) print(" '%s'", *argv++); print(" "); exits(0); } Here is the output for the run prog -bffile1 -r -f file2 arg1 arg2 prog -b -f(file1) badflag('r') -f(file2) 2 args: 'arg1' 'arg2' This Alef program accepts options b and, with an attached file name, f. #include <alef.h> void main(int argc, byte **argv) { int a, ac, bflag; byte *file; Arg *arg; arg = arginit(argc, argv); while(ac = argopt(arg)) switch(ac){ case 'b': bflag = 1; break; case 'f': file = argf(arg); break; } for(a=0; a<arg->ac; a++) print("argument %s ", arg->av[a]); } SOURCE
/sys/include/libc.h ARG(2)
All times are GMT -4. The time now is 02:45 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy