Sponsored Content
Full Discussion: Command Line Argument
Top Forums Programming Command Line Argument Post 302332295 by dsudipta on Wednesday 8th of July 2009 03:48:44 PM
Old 07-08-2009
Command Line Argument

Hi,

I have a very simple C program which will run in UNIX. When i am passing * as the command line argument, i am gettig the below output.

Program:
#include <stdio.h>
#include "mylibrary.h"

int **environ;

int main(int argc,char *argv[])
{
int i;
printf("\nHello World");
printf("\nNumber of arguments: %d\n",argc);

for(i=0;i<argc;i++)
{
printf("\nArgument # %d is: %s\n",i,argv[i]);
}

return 1;
}

Compile:
cc hello.c -o hello

Run:
./hello *

Output:
Hello World
Number of arguments: 5

Argument # 0 is: ./hello

Argument # 1 is: hello

Argument # 2 is: hello.c

Argument # 3 is: mylibrary.h

Can somebody please explain me what is the exact reason of this output.

Thanks
Sudipta.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

array as command line argument !!!!

hello, can any help me how to can pass array as command line argument in korn shell. also how to read a array from command line. thanks spandu (2 Replies)
Discussion started by: spandu
2 Replies

2. Shell Programming and Scripting

How to get the value in last command line argument???

Say I want to get the value of last command line argument using the value in $# (or some other way if u can suggest) how do I do it?? $"$#" `$"$#"` These don't work :( (4 Replies)
Discussion started by: amit_oddey21
4 Replies

3. Shell Programming and Scripting

assign a command line argument and a unix command to awk variables

Hi , I have a piece of code ...wherein I need to assign the following ... 1) A command line argument to a variable e.g origCount=ARGV 2) A unix command to a variable e.g result=`wc -l testFile.txt` in my awk shell script When I do this : print "origCount" origCount --> I get the... (0 Replies)
Discussion started by: sweta_doshi
0 Replies

4. Shell Programming and Scripting

Need Help with the argument passing Through Command line

$$$$$ (5 Replies)
Discussion started by: asirohi
5 Replies

5. Shell Programming and Scripting

finding * in command line argument

I have to write a script to determine whether given command line argument ($1) contains "*" symbol or not, if $1 does not contains "*" symbol add it to $1, otherwise show message "Symbol is not required". For e.g. If we called this script q5 then after giving , $ q5 /bin Here $1 is /bin, it... (5 Replies)
Discussion started by: cynosure2009
5 Replies

6. Shell Programming and Scripting

command-line line 0: Missing yes/no argument

Hi Guys When I run the below command ssh -o 'PasswordAuthentication yes' -o 'PreferredAuthentications publickey' -i $HOME/.ssh/id_dsa Server_Name I found the below error ommand-line line 0: Missing yes/no argument Kindly help me to sort out Double post, continued... (0 Replies)
Discussion started by: Pratik4891
0 Replies

7. Shell Programming and Scripting

Help on command line argument in csh

HI , I am new to csh. I need to pass some command line arguments like ./abc.sh -os Linux -path abc -tl aa -PILX 1 I have defined the loop as shown below. But its taking "-os" switches as arguments. Its treating them as arguments. How to resolve it? while ( $#argv != 0 ) switch ($argv) ... (7 Replies)
Discussion started by: vineet.dhingra
7 Replies

8. Shell Programming and Scripting

Can a string be a command line argument?

I would like to use a string as a command line argument...is this possible using TCSH? For example say my script is called TEST and I would like to pass a string into my script stating why the test failed. EXAMPLE: TEST "Failed due to missing statement" (4 Replies)
Discussion started by: thibodc
4 Replies

9. Shell Programming and Scripting

Specify an entire UNIX command as a command line argument

I'm trying to write a bash script called YN that looks like the following YN "Specify a question" "doThis" "doThat" where "doThis" will be executed if the answer is "y", otherwise "doThat". For example YN "Do you want to list the file dog?" "ls -al dog" "" Here's my attempt... (3 Replies)
Discussion started by: LeoKSimon
3 Replies

10. UNIX for Beginners Questions & Answers

Command line argument

Hi Guys, I'm trying to work out how to add a command line argument inside single quotes. Would anyone be able to help please as I'm going mad :) I want to be able to place the filename on command line and it then be used in a script but it needs to have quotes surrounding it. Thanks in... (4 Replies)
Discussion started by: mutley2202
4 Replies
SVK::Command(3) 					User Contributed Perl Documentation					   SVK::Command(3)

NAME
SVK::Command - Base class and dispatcher for SVK commands SYNOPSIS
use SVK::Command; my $xd = SVK::XD->new ( ... ); my $cmd = 'checkout'; my @args = qw( file1 file2 ); open my $output_fh, '>', 'svk.log' or die $!; SVK::Command->invoke ($xd, $cmd, $output_fh, @args); DESCRIPTION
This module resolves alias for commands and dispatches them, usually with the "invoke" method. If the command invocation is incorrect, usage information is displayed instead. METHODS
Class Methods invoke ($xd, $cmd, $output_fh, @args) Takes a SVK::XD object, the command name, the output scalar reference, and the arguments for the command. The command name is translated with the %alias map. On Win32, after @args is parsed for named options, the remaining positional arguments are expanded for shell globbing with "bsd_glob". getopt ($argv, %opt) Takes a arrayref of argv for run getopt for the command, with additional %opt getopt options. Instance Methods "SVK::Command->invoke" loads the corresponding class "SVK::Command::$name", so that's the class you want to implement the following methods in: options () Returns a hash where the keys are Getopt::Long specs and the values are a string that will be the keys storing the parsed option in $self. Subclasses should override this to add their own options. Defaults to an empty list. opt_recursive Defines if the command needs the recursive flag and its default. The value will be stored in "recursive". parse_arg (@args) This method is called with the remaining arguments after parsing named options with "options" above. It should use the "arg_*" methods to return a list of parsed arguments for the command's "lock" and "run" method to process. Defaults to return a single "undef". lock (@parse_args) Calls the "lock_*" methods to lock the SVK::XD object. The arguments will be what is returned from "parse_arg". run (@parsed_args) Actually process the command. The arguments will be what is returned from "parse_arg". Returned undef on success. Return a string message to notify the caller errors. Utility Methods Except for "arg_depotname", all "arg_*" methods below returns a SVK::Path object, which consists of a hash with the following keys: cinfo copath depotpath path repos repospath report targets The hashes are handy to pass to many other functions. arg_condensed (@args) Argument is a number of checkout paths. arg_uri_maybe ($arg, $no_new_mirror) Argument might be a URI or a depotpath. If it is a URI, try to find it at or under one of currently mirrored paths. If not found, prompts the user to mirror and sync it. arg_co_maybe ($arg, $no_new_mirror) Argument might be a checkout path or a depotpath. If argument is URI then handles it via "arg_uri_maybe". arg_copath ($arg) Argument is a checkout path. arg_depotpath ($arg) Argument is a depotpath, including the slashes and depot name. arg_depotroot ($arg) Argument is a depot root, or a checkout path that needs to be resolved into a depot root. arg_depotname ($arg) Argument is a name of depot. such as '' or 'test' that is being used normally between two slashes. arg_path ($arg) Argument is a plain path in the filesystem. apply_revision($target) Apply the given revision from command line to $target. parse_revlist () Parse -c or -r to a list of [from, to] pairs. lock_target ($target) XXX Undocumented lock_coroot ($target) XXX Undocumented brief_usage ($file) Display an one-line brief usage of the command object. Optionally, a file could be given to extract the usage from the POD. filename Return the filename for the command module. usage ($want_detail) Display usage. If $want_detail is true, the "DESCRIPTION" section is displayed as well. Error Handling handle_error ($error) XXX Undocumented add_handler ($error, $handler) XXX Undocumented msg_handler ($error, $message) XXX Undocumented msg_handler ($error) XXX Undocumented command ($cmd, \%args) Construct a command object of the $cmd subclass and return it. The new object will share the "xd" from the calling command object; contents in %args is also assigned into the new object. rebless ($cmd, \%args) Like "command" above, but modifies the calling object instead of creating a new one. Useful for a command object to recast itself into another command class. run_command_recursively($target, $code) Traverse $target and and invoke $code with each node. SEE ALSO
SVK, SVK::XD, "SVK::Command::*" perl v5.10.0 2008-08-04 SVK::Command(3)
All times are GMT -4. The time now is 03:57 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy